Skip to main content

Other Data Related Interfaces.

Customize the app version number

The Tingyun App SDK by default uses the "versionName" of the application as the version number for uploading. If you need to customize the version number, you can configure it by calling this interface during SDK initialization.

  • Related Interface
/**
*@param versionName Up to 64 characters are allowed, supporting Chinese, English, numbers, and underscores.
*/
NBSAppAgent.setVersionName(String versionName);
  • Code Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.setVersionName("v2.11.1")//Call the interface to set the version number during SDK initialization.
.start(this.getApplicationContext());
}
}

Customize the channel

Developers can set a custom channel name during the initialization of the Tingyun App SDK.

  • Related Interface
/**
* @param channelID ChannelID。
* It can consist of English letters, Arabic numerals, underscores, hyphens, spaces, parentheses, and can include Chinese characters and other plaintext characters. However, it's not recommended to use Chinese characters in naming, as it may result in garbled text.
* The leading and trailing characters cannot be spaces. Avoid using pure numbers as channel IDs. Maximum of 256 characters.
*/
NBSAppAgent.setChannelID(String channelID);
  • Code Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.setChannelID("应用宝")//Call the interface to set the version number during SDK initialization.
.start(this.getApplicationContext());
}
}

Set geographical location information.

You can set latitude and longitude through the interface to accurately obtain device geographical location information.

  • Related Interface
/**
* @param lat Latitude
* @param lng Longitude
*/
NBSAppAgent.setLatLng(double lat, double lng);
  • Code Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLatLng(39.936846,116.39277);// Set latitude and longitude.
}
}

Enable SDK Log

After calling the interface, SDK INFO logs can be printed.

  • Related Interface
/**
* @param enable By default, it's set to false. Setting it to true will output logs.
*/
NBSAppAgent.setLogEnable(boolean enable);
  • Code Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.start(this.getApplicationContext());

NBSAppAgent.setLogEnable(true);//设置成 true,输出日志
}
}

Only collect data in the main process.

The App SDK collects data from all processes by default during Application initialization. It also supports setting to only collect data from the main process.

  • Related Interface
/**
* @param enable By default, it's set to false. Setting it to true will only collect data from the main process.
*/
NBSAppAgent.withOnlyMainProcEnabled(boolean enable);
  • Code Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.withOnlyMainProcEnabled(true)//Set to true to only collect data from the main process.
.start(this.getApplicationContext());
}
}

Enable module functionality switch on first startup.

For compatibility reasons, on the first startup, the SDK enables all functional modules only in debug mode. In non-debug mode, it only enables the crash module. You can use the following interface to toggle the module functionality of the SDK: Module Function Switch Interface.

  • Related Interface
/**
* @param option The status value of the switch.
* SDK The following switches are defined
* Network data collection
* NBSAppAgent.HTTP_NETWORK_ENABLED = 1;
* UI data collection (startup, page, interaction data)
* NBSAppAgent.UI_ENABLED = 2;
* Crash data collection
* NBSAppAgent.CRASH_ENABLED = 4;
* WebView data collection
* NBSAppAgent.WEBVIEW_ENABLED = 8;
* Socket Hook
* NBSAppAgent.SOCKET_DATA_ENABLED = 16;
* Cross-application functionality
* NBSAppAgent.CROSS_APP_ENABLED = 32;
* ANR data collection
* NBSAppAgent.ANR_ENABLED = 64;
* Behavior data collection
* NBSAppAgent.USER_ACTION_ENABLED = 128;
* CDN data collection
* NBSAppAgent.CDN_ENDBLED = 256;
* Video recording collection
* NBSAppAgent.RECORD_ENDBLED = 512;
* Full trace collection
* NBSAppAgent.ALL_TRACE_COLLECT_ENDBLED = 1024;
* Rapid click collection
* NBSAppAgent.VIOLENCE_ENDBLED = 2048;
* Log Fetch
* NBSAppAgent.LOG_MODULE_ENABLED = 4096;
* OOM collection
* NBSAppAgent.OOM_MODULE_ENABLED = 8192;
* Power consumption collection
* NBSAppAgent.BATTERY_MODULE_ENABLED = 16384;
* Abnormal power consumption collection
* NBSAppAgent.BATTERY_ERROR_ENABLED = 32768;
* Network content collection
* NBSAppAgent.RECORD_NETWORK_ENABLE = 65536;
* CPU data collection
* NBSAppAgent.CPU_MODULE_ENABLED = 131072;
* FPS collection
* NBSAppAgent.FPS_MODULE_ENABLED = 262144;
*/
NBSAppAgent.setStartOption(int option);
  • Code Example
public void onCreate() {  
NBSAppAgent.setLicenseKey("AppKey")
.setStartOption(NBSAppAgent.HTTP_NETWORK_ENABLED | NBSAppAgent.UI_ENABLED | NBSAppAgent.CRASH_ENABLED)
//Enable network, UI, and crash data collection on first startup.
.start(this.getApplicationContext());
}

Get the Tingyun device ID

Upon the initial startup of the application, the Tingyun server will issue a deviceId to identify the device. Users can obtain the deviceId value from the Tingyun through an interface.

  • Related Interface
/**
* @return Return the Tingyun device ID
*/
NBSAppAgent.getTingyunDeviceId()
  • Code Example
public void onCreate() {  
String tingYunDid = NBSAppAgent.getTingyunDeviceId();
if(!TextUtils.isEmpty(tingYunDid)){//If the deviceId does not exist, return null. It is recommended to check for null before usage.
...
}
}

Ignore Tingyun Scheme configuration

The Tingyun Scheme is designed for application developers and operators to visually name the pages and operations data collected by the SDK, which may trigger a popup requesting overlay permission. For Scheme activation, we recommend defining a separate Scheme. If other applications have already used the Tingyun Scheme to launch your application, you can use the setIgnoreScheme() method to specify the Scheme, and the SDK will no longer enable the visual configuration function for that Scheme.

  • Related Interface
/**
* @param scheme Pass the ignored scheme value.
*/
NBSAppAgent.setIngoreScheme(String scheme);
  • Code Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.setIngoreScheme("tingyun.1234")//Call the interface to set the scheme value to be ignored during SDK initialization.
.start(this.getApplicationContext());
}
}

Set the okhttp3.EventListener switch

If your project integrates OkHttp3.11.0 or above, the Tingyun SDK will collect data through EventListener. If your project also sets EventListener, the Tingyun SDK will record the previous EventListener when it is replaced. When the Tingyun SDK receives relevant callback methods, it will callback to the project's EventListener, so it will not affect the project's own EventListener from receiving callbacks. If you do not want the Tingyun SDK to set EventListener, you can disable it through the setOkhttpTcpListener() method.

  • Related Interface
/**
* @param isSetListener By default, it's set to true. Setting it to false disables setting EventListener.
*/
NBSAppAgent.setOkhttpTcpListener(boolean isSetListener);
  • Code Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.setOkhttpTcpListener(false)// Call the interface during SDK initialization to prevent the SDK from setting EventListener
.start(this.getApplicationContext());
}
}

Retrieve the project's EventListener

If your project integrates OkHttp3.11.0 or above, the Tingyun SDK will collect data through EventListener. If your project also sets EventListener, the Tingyun SDK will record the previous EventListener when it is replaced. If you retrieve the EventListener through reflection in the code, it will return the Tingyun EventListener. You can retrieve your project's EventListener by using the NBSHttpTcpListener.getListener() method.

  • Related Interface
/**
* @return Return the EventListener replaced by the SDK.
*/
NBSHttpTcpListener.getListener()
  • Code Example
// HttpEventListener Indicate the project's own EventListener.
HttpEventListener listener = null;
try {
if (mEventListenerField == null) {
synchronized (this) {
if (mEventListenerField == null) {
Class<?> realCallClass = call.getClass();
mEventListenerField = realCallClass.getDeclaredField("eventListener");
mEventListenerField.setAccessible(true);
}
}
}
// listener = (HttpEventListener) mEventListenerField.get(call);// If you directly cast the Tingyun listener to your own listener, it may throw an exception.
EventListener eventListener = (EventListener) mEventListenerField.get(call);// Retrieve EventListener through reflection.
if (eventListener instanceof HttpEventListener) { // To determine whether the eventListener belongs to your own or to Tingyun's, you can compare the class types or check for specific characteristics that differentiate them.
listener = (HttpEventListener) eventListener;// If it's your own listener, cast it to your own.
}else if (eventListener instanceof NBSHttpTcpListener){
NBSHttpTcpListener nbsHttpTcpListener = (NBSHttpTcpListener) eventListener;// If it's Tingyun's listener, cast it to Tingyun's.
listener = (HttpEventListener) nbsHttpTcpListener.getListener();// Retrieve your own listener through Tingyun's getListener() method.
}
} catch (Exception e) {
}

Set OAID

If your project integrates the OAID SDK, you can pass the obtained OAID to the Tingyun SDK to generate the device ID.

Note: Due to privacy concerns, on some devices, the OAID may return a fixed value, such as 00000000-0000-0000-0000-000000000000 or 0000000000000000000000000000000000000000000000000000000000000000. Please do not pass fixed values to the SDK.

  • Related Interface
/**
* @param oaid The OAID passed in.
*/
NBSAppAgent.setOaidData(String oaid)
  • Code Example
NBSAppAgent.setOaidData("e6ee0f4b6b67cf8b")

Filtering okhttp3.ResponseBody embedding

The Tingyun SDK replaces okhttp3.ResponseBody to collect downloaded byte counts. If there are type conversion operations in your project's code after obtaining response.body(), it may trigger exceptions. You can use the setOkhttpResponseBodyFilter() interface to filter okhttp3.ResponseBody embedding.

  • Related Interface
/**
* @param className For the fully qualified class name of the ResponseBody that needs to be filtered, this class cannot be obfuscated.
*/
NBSAppAgent.setOkhttpResponseBodyFilter(String className)
  • Code Example
NBSAppAgent.setOkhttpResponseBodyFilter("com.xxx.okhttptest.util.ProgressResponseBody")// Pass the fully qualified class name of the ResponseBody to be filtered.

Disable HarmonyOS device identification.

On HarmonyOS devices, the SDK initializes by setting the operating system to "HarmonyOS". You can use this interface to disable the SDK's recognition of HarmonyOS settings. Once disabled, the SDK will set the operating system to "Android".

If you're using a private platform, you need to confirm whether the platform supports HarmonyOS device recognition. If the platform doesn't support HarmonyOS device recognition, you need to call isHarmonyOs(false).

  • Related Interface
/**
* @param isHarmonyOS Is HarmonyOS device recognition enabled, default is true.
*/
NBSAppAgent.isHarmonyOs(boolean isHarmonyOS)
  • Code Example
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host")
.isHarmonyOs(false)// Disable HarmonyOS device identification
.start(getApplicationContext());

Retrieve user identifier

By adding a "user identifier", you can retrieve specific user performance issues on the Tingyun reporting platform through this identifier.

  • Related Interface
/**
* @param userIdentifier It can contain up to 256 characters, including Chinese, English, numbers, and underscores, but cannot contain spaces or other escape characters.
*/
NBSAppAgent.setUserIdentifier(String userIdentifier);
  • Code Example
public class MainActivity extends Activity {  
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String userIdentifier = getUserID();
NBSAppAgent.setLicenseKey("AppKey")
.start(this.getApplicationContext());
//The user identifier can be an email address, phone number, or any other information that can identify the user's identity, such as: xxx@tingyun.com
NBSAppAgent.setUserIdentifier(userIdentifier);
}
}

The SDK transmits data using SM encryption

The SDK supports SM encryption for data transmission. Call this interface to enable SM encryption.

Note:

-SM encryption is only supported on Android 6.0 and above. When SM encryption is enabled, SDKs for Android versions 5.x and below will not collect data.。

  • Enabling SM encryption requires integration bcpkix-jdk15to18-version.jar 和 bcprov-jdk15to18-version.jar 。

  • The server-side also needs to enable SM encryption functionality in synchronization.

  • Related Interface
/**
* param isEncryptionRequired By default, it's set to false. Setting it to true enables SM encryption.
*/
NBSAppAgent.encryptionRequired(boolean isEncryptionRequired)
  • Code Example
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host")
.encryptionRequired(true)// enable SM encryption
.start(this.getApplicationContext());

Disable mobile carrier data collection

The SDK collects mobile network operator information through TelephonyManager.getSimOperator(). You can control whether to collect this information by calling the isOperatorCollect() interface during SDK initialization.

  • Related Interface
/**
* @param isCollect By default, it's set to true. Setting it to false disables carrier data collection.
*/
NBSAppAgent.isOperatorCollect(boolean isCollect)NBSAppAgent.isOperatorCollect(boolean isCollect)
  • Code Example
NBSAppAgent.setLicenseKey("AppKey").setRedirectHost("Host")
.isOperatorCollect(false)// Disable mobile carrier data collection
.start(this.getApplicationContext());

Set the base station data collection switch.

You can control whether to enable base station data collection through the setCellCollectEnabled() interface. This interface should be called before SDK initialization.

Starting from version 2.17.4, the SDK has disabled base station data collection by default.

  • Related Interface
/**
* @param enable The default setting for base station data collection switch is true. You can set it to false to disable collection.
*/
NBSAppAgent.setCellCollectEnabled(boolean enable);
  • Code Example
NBSAppAgent.setCellCollectEnabled(false);// 关闭基站数据采集

Set the business line name

You can use the "Set Business Line" interface to differentiate crashes, ANRs, and network errors by business lines, enabling you to view performance data for specific businesses.

  • Related Interface
/**
* @param key:Fixed to bname
* @param value:The business name that needs to be set.
*/
NBSAppArent.setBusinessLine(String key, String value);
  • Code Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppArent.setBusinessLine("bname", "Shopping Cart");
}
}