Java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Obtain the HiAnalyticsInstance instance.
HiAnalyticsInstance instance = HiAnalytics.getInstance(this);
}
Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Obtain the HiAnalyticsInstance instance.
val instance = HiAnalytics.getInstance(this)
}
Skip this step if you use the visual event function to add events.
Java
// Customize an event to report.
// Set the custom event name to Purchase.
String eventName = "Purchase";
// Customize event parameters.
Bundle bundle = new Bundle();
// Set a value of the Double type.
bundle.putDouble("price", 9.99);
// Set a value of the Long type.
bundle.putLong("quantity", 100L);
// Set a value of the String type.
bundle.putString("currency", "CNY");
// Report events.
if (instance != null) {
instance.onEvent(eventName, bundle);
}
Kotlin
// Customize an event to report.
// Set the custom event name to Purchase.
val eventName = "Purchase"
// Customize event parameters.
val bundle = Bundle()
bundle.apply {
// Set a value of the Double type.
putDouble("price", 9.99)
// Set a value of the Long type.
putLong("quantity", 100L)
// Set a value of the String type.
putString("currency", "CNY")
}
// Report events.
instance?.let {
it.onEvent(eventName, bundle)
}
Command for enabling the debug mode: adb shell setprop debug.huawei.hms.analytics.app <package_name>
Command for disabling the debug mode: adb shell setprop debug.huawei.hms.analytics.app .none.
Command for enabling the debug mode: adb shell setprop debug.firebase.analytics.app <package_name>
Command for disabling the debug mode: adb shell setprop debug.firebase.analytics.app .none.
Command for enabling the debug mode: adb shell setprop debug.huawei.hms.dtm.app <package_name>
Command for disabling the debug mode: adb shell setprop debug.huawei.hms.dtm.app .none.
For details about debugging operations in AppGallery Connect, please refer to App Debugging.
During development, you can enable the debug mode to view the event records in real time, observe the results, and adjust the event tracking scheme as needed.
The following uses HUAWEI Analytics as an example:
adb shell setprop debug.huawei.hms.analytics.app <package_name> After the debug mode is enabled, all events will be reported in real time.
Successfully reported data is displayed on HUAWEI Analytics in real time, as shown in the screenshot below.

You can click View in the Details column of an event ID to view the event details.


adb shell setprop debug.huawei.hms.analytics.app.none.