All Products
Search
Document Center

Mobile Platform as a Service:Android client development

Last Updated:Sep 15, 2023

This topic describes how to develop custom event anlaysis function 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

import com.mpaas.mas.adapter.api.MPLogger;

import java.util.HashMap;
import java.util.Map;

// Specify the business ID
String bizType = "Pay";
// Event ID
String logId = "PayResults";
// Add attributes
Map<String, String> params = new HashMap<>(4);
// Attribute: payment time. Key corresponds to the attribute ID and Value corresponds to the attribute value.
params.put("pay_time", String.valueOf(System.currentTimeMillis()));
// Attribute: user ID
params.put("user_id", "the-userId");
// Attribute: payment mode
params.put("payment_method", "alipay");
// Print logs
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:

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