Android client development

更新时间:
复制 MD 格式

Integrate mPaaS mobile analytics into your Android app to record and report event logs.

To integrate mobile analytics into your Android client:

  1. Integrate the mobile analytics component

  2. Record event logs

  3. Report logs

1. Integrate the mobile analytics component

Follow the Android integration guide to add the mobile analytics component.

2. Record event logs

The following example records an event log with custom properties.

Sample code

This example records an event with the business ID, event ID, payment time, user ID, and payment method.

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

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

// Business ID
String bizType = "Pay";
// Event ID
String logId = "PayResults";
// Add properties
Map<String, String> params = new HashMap<>(4);
// Property: Payment time. The key is the property ID. The value is the property value.
params.put("pay_time", String.valueOf(System.currentTimeMillis()));
// Property: User ID
params.put("user_id", "the-userId");
// Property: Payment method
params.put("payment_method", "alipay");
// Log the event
MPLogger.event(logId, bizType, params);

Parameter descriptions

Parameter

Description

bizType

The business ID (also called business code or business type). Uniquely identifies a business. Set to Pay in this example to represent the payment business.

The bizType affects the client log file name. The log file name follows the format: timestamp_package-name-process_bizType.

logId

Uniquely identifies an event. Tutorial scenarios.

params

Stores event properties in params.put("param-key", "param-value") format.

  • param-key: The property ID. Defined in Tutorial scenarios.

  • param-value: The property value. Stored as a string on the client. The server automatically converts it to string, integer, or floating-point type for analysis.

3. Report logs

Local logs are automatically reported when the cache reaches a threshold or the app runs in the background for a set period. To immediately report logs during development and testing, call:

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

Related links