All Products
Search
Document Center

Android client development

Last Updated: Mar 24, 2021

This topic describes how to develop custom event anlaysis funciton on the Android client, including:

  1. Access Mobile Analysis Service
  2. Record event logs
  3. Report logs

1. Access Mobile Analysis Service

Access Mobile Analysis Service by referring to Access Android - Quick start guide.

2. Record event logs

The section guides you how to record event logs through a code sample, and gives introduction about the parameters involved in the code sample.

Code sample

 
  1. import com.mpaas.mas.adapter.api.MPLogger;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. // Specify the business ID
  5. String bizType = "Pay";
  6. // Event ID
  7. String logId = "PayResults";
  8. // Add attributes
  9. Map<String, String> params = new HashMap<>(4);
  10. // Attribute: payment time. Key corresponds to the attribute ID and Value corresponds to the attribute value.
  11. params.put("pay_time", String.valueOf(System.currentTimeMillis()));
  12. // Attribute: user ID
  13. params.put("user_id", "the-userId");
  14. // Attribute: payment mode
  15. params.put("payment_method", "alipay");
  16. // Print logs
  17. MPLogger.event(logId, bizType, params);

Instructions on parameters

  • bizType (business ID)

    • bizType specifies the business ID (also known as business code or business type), which is the unique identifier of a business. In the code sample, bizType is set to Pay, indicating payment business.
    • bizType affects the log file name on the client. The log file naming format is timestamp_package name-process_bizType.
  • logId (event ID)
    logId specifies the event ID, which is the unique identifier of an event. For more information, see the description of tutorial scenario in About this tutorial.

  • params (event attribute)
    params stores attributes associated with events. In params.put("param-key", "param-value"):

    • param-key: corresponding to the attribute ID. For more information, see the description of tutorial scenario in About this tutorial.
    • Param-value: corresponding to the attribute value. The attribute value is stored as a character string on the client. In actual analysis, the server supports converting the attribute value into a character, integer, or float value.

3. Report logs

By default, when logs cached on the client reach a certain number or the program runs in the backend for a certain period of time, local logs are automatically reported to the Mobile Analysis server. During development testing, you can call the following APIs to forcibly report local logs to the server immediately:

 
  1. import com.mpaas.mas.adapter.api.MPLogger;
  2. MPLogger.uploadAll();