Session
Start a New Session
Call this interface to start a new session.
- Related interface
NBSAppAgent.startNextSession();
- Code example
NBSAppAgent.startNextSession(); // Start a new session
Get Session ID
Call this interface to get the current session ID.
- Related interface
/**
* @return Session ID.
*/
NBSAppAgent.getSessionId();
- Code example
NBSAppAgent.getSessionId(); // Returns the session ID
Set Session Idle Time
If idle for more than 600 seconds, the SDK will regenerate the session ID. It is recommended to set this before SDK initialization.
- Related interface
/**
* @param sessionIdleTime 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 700 seconds of idleness
Custom Event
You can upload custom events using the reportEvent() interface.
- Related interface
/**
* @param name Event name.
* @param attributes 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 (start, pause, resume) by calling the interface.
- Related interface
/**
* Start video recording
*/
NBSAppAgent.startVideoReplay()
/**
* Pause video recording
*/
NBSAppAgent.pauseVideoReplay()
/**
* Resume video recording
*/
NBSAppAgent.resumeVideoReplay()
- Code example
The following example starts video recording when entering the home page, pauses when submitting an order, and resumes when leaving the order page.
// Enter home page
public void initHomeViews() {
...
NBSAppAgent.startVideoReplay();
}
// Submit order
public void submitOrders() {
...
NBSAppAgent.pauseVideoReplay();
}
// Leave order page
public void dismissOrderPage() {
...
NBSAppAgent.resumeVideoReplay();
}
Sensitive Information Masking
You can use the sensitive information masking interface to mask sensitive information at a finer granularity (viewId, page, class name, region).
- Related interface
/**
* @param view The view to mask.
*/
NBSAppAgent.maskSensitiveRegion(View view);
/**
* @param view The view to unmask.
*/
NBSAppAgent.unMaskSensitiveRegion(View view);
/**
* @param rect The region to mask.
*/
NBSAppAgent.maskSensitiveRegion(Rect rect);
/**
* @param rect The region to unmask.
*/
NBSAppAgent.unMaskSensitiveRegion(Rect rect);
/**
* @param clazz The class to mask.
*/
NBSAppAgent.maskClass(Class clazz);
/**
* @param pageName The page name to mask. Pass the Activity or Fragment class name (NBSAppAgent.class.getName()).
*/
NBSAppAgent.maskScreens(String pageName);
/**
* @param viewId The View's id to mask, i.e., R.id.xxx.
*/
NBSAppAgent.maskViewId(int viewId);
/**
* @param viewId The View's id to mask, set via 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 class
NBSAppAgent.maskScreens(MainActivity.class.getName()); // Mask the MainActivity page
NBSAppAgent.maskViewId(R.id.tv); // Mask the View with id R.id.tv
NBSAppAgent.maskViewId("tv_name"); // Mask the View with id tv_name