Session Interfaces
Start New Session
Calling this interface can start a new session.
- Related Interface
NBSAppAgent.startNextSession();
- Code Example
NBSAppAgent.startNextSession();// Start a new session
Get Session ID
Calling this interface retrieves the current session ID.
- Related Interface
/**
* @return Session id。
*/
NBSAppAgent.getSessionId();
- Code Example
NBSAppAgent.getSessionId();// Returns the session id
Set Session Idle Time
After being idle for more than 600 seconds, the SDK will generate a new session ID. It is recommended to set this before SDK initialization.
- Related Interface
/**
* @param sessionIdleTime The session idle time in seconds. Default is 600 seconds. The minimum supported time is 60 seconds. Set to 0 to disable idle time.
*/
NBSAppAgent.setSessionIdleTime(long sessionIdleTime);
- Code Example
NBSAppAgent.setSessionIdleTime(700); // Generate a new session ID after being idle for 700 seconds
Custom Events
You can upload custom events through the reportEvent() interface.
- Related Interface
/**
* @param name The event name.
* @param attributes The event attributes.
*/
NBSAppAgent.reportEvent(String name, Map attributes);
- Code Example
Map map = new HashMap();
map.put("name","zhangsan")
NBSAppAgent.reportEvent("login", map);
Screen Recording
You can control screen recording by calling the interface to start, pause, or resume.
- Related Interface
/**
* Start video recording
*/
NBSAppAgent.startVideoReplay()
/**
* Pause video recording
*/
NBSAppAgent.pauseVideoReplay()
/**
* Resume video recording
*/
NBSAppAgent.resumeVideoReplay()
- Code Example
The following example starts screen recording when entering the homepage, pauses screen recording when submitting an order, and resumes screen recording when leaving the order page.
//Enter the homepage
public void initHomeViews(){
...
NBSAppAgent.startVideoReplay();
}
//Submit orders
public void submitOrders(){
...
NBSAppAgent.pauseVideoReplay();
}
// Leave the order page
publice void dismissOrderPage(){
...
NBSAppAgent.resumeVideoReplay();
}
Sensitive Information Masking
You can use the sensitive information masking interface to mask sensitive information at a more granular level, including "viewId, page, class name, and region".
- Related Interface
/**
* @param view The view to be masked.
*/
NBSAppAgent.maskSensitiveRegion(View view);
/**
* @param view The view to be unmasked.
*/
NBSAppAgent.unMaskSensitiveRegion(View view);
/**
* @param view The region to be masked.
*/
NBSAppAgent.maskSensitiveRegion(Rect rect);
/**
* @param view The region to be unmasked.
*/
NBSAppAgent.unMaskSensitiveRegion(Rect rect);
/**
* @param clazz The class to be masked.
*/
NBSAppAgent.maskClass(Class clazz)
/**
* @param pageName The name of the page to be masked, pass NBSAppAgent.class.getName() for the Activity or Fragment to be masked.
*/
NBSAppAgent.maskScreens(String pageName)
/**
* @param viewId The id of the View to be masked, i.e., R.id.xxx.
*/
NBSAppAgent.maskViewId(int viewId)
/**
* @param viewId The id of the View to be masked, set id for the View using NBSAppAgent.setViewId(View view, String viewId).
*/
NBSAppAgent.maskViewId(String viewId)
- Code Example
Button bt_login = findViewById(R.id.login);
NBSAppAgent.maskSensitiveRegion(bt_login);// Mask the bt_login button
Rect rect = new Rect(100,100,800,800);
NBSAppAgent.maskSensitiveRegion(rect);// Mask the rect region
... ...
NBSAppAgent.unMaskSensitiveRegion(bt_login);// Unmask the bt_login button
NBSAppAgent.unMaskSensitiveRegion(rect);// Unmask the rect region
... ...
NBSAppAgent.maskClass(Button.class);// Mask the Button
NBSAppAgent.maskScreens(MainActivity.class.getName());// Mask the MainActivity
NBSAppAgent.maskViewId(R.id.tv);// Mask the View with id R.id.tv
NBSAppAgent.maskViewId("tv_name");// 对 Mask the View with id tv_name