Android SDK docs
Overview
App Analytics is a separate product line: launches, screens, versions, channels, crashes, ANRs and launch time have their own events and definitions — Web PV and bounce rate do not apply. Web pages embedded in the app can keep using Web Analytics.
Download the SDK
Using the Maven repository is recommended (see the next section). If you cannot reach it, put the SDK AAR into app/libs/ — crash capture depends on xCrash, so manual integration needs both AARs.
Maven repository: http://a.t3j.com/maven/
The demo app includes the SDK; install it on a phone and tap the buttons to try custom events, screen changes, crashes and ANRs.
Gradle setup
Add the Fmeng Maven repository to dependencyResolutionManagement.repositories in settings.gradle; mavenCentral() is needed for xCrash:
Then add the dependency to app/build.gradle:
ProGuard rules ship with the AAR (consumer rules), so nothing needs to go into proguard-rules.pro; the INTERNET and ACCESS_NETWORK_STATE permissions are merged into your AndroidManifest automatically.
Initialization
As with Umeng, the App Key and channel go under <application> in AndroidManifest.xml: FMENG_APPKEY is the APP_KEY (see "App settings - Basic info"; the "Setup code" tab fills it in for you) and FMENG_CHANNEL is the install channel (optional, used by the Versions & channels report).
For multi-channel builds set FMENG_CHANNEL to ${FMENG_CHANNEL} and fill it per productFlavor, so each channel build carries its own channel:
Then initialize as early as possible in Application.onCreate so the SDK can measure cold starts and catch crashes during startup. The SDK reads the App Key and channel from AndroidManifest; with default options just call Fmeng.init(this).
If you have no custom Application, create one and declare it in <application android:name=".MyApplication"> of AndroidManifest.xml.
You can also skip the meta-data and pass them in code: new FmengConfig.Builder("APP_KEY").channel("huawei"). Values set in code take precedence over AndroidManifest.
Options
Options (the App Key and channel can also be set as AndroidManifest meta-data; values in code take precedence):
| Attribute | Default | Description |
|---|---|---|
FMENG_APPKEY / Builder(appKey) | Required | The APP_KEY generated when you created the app in the console. |
FMENG_CHANNEL / channel(String) | Empty | Install channel (e.g. huawei, xiaomi, official), used by the Versions & channels report. |
FMENG_REGION / region(String) | Global | Collection node: cn reports to the China mainland node, for apps whose users are mostly in mainland China (1.2.0+). Both nodes feed the same console. |
debug(boolean) | false | Log sending to logcat; pass BuildConfig.DEBUG. |
crashReport(boolean) | true | Capture Java and Native crashes (xCrash); sent on the next launch. |
anrReport(boolean) | true | Capture ANRs (App Not Responding); sent on the next launch. |
autoTrackScreens(boolean) | true | Record each Activity as a screen view; use trackScreen for Fragment / Compose screens. |
sessionTimeoutMillis(long) | 30000 | Returning to the foreground after this long in the background counts as a new launch (session). |
Manual APIs
Business events, manual screens and signed-in users. Property values can be strings, numbers or booleans:
After setEnabled(false) the SDK stops collecting and sending (e.g. before the user accepts your privacy policy); call setEnabled(true) to resume.
HTTP collection address
Since Android 9 (API 28), cleartext HTTP is blocked by default. If the collection address is http, allow cleartext traffic for its domain: create res/xml/network_security_config.xml and reference it on <application> in AndroidManifest. Skip this step for https addresses.
Auto-collected events
The SDK collects the following events automatically. Events are written to a local queue (up to 1,000), sent in gzip batches and retried with exponential backoff; crashes are written to disk synchronously and sent on the next launch.
| Event | Fired when | Key fields |
|---|---|---|
launch | Cold, warm and hot starts | launch_type, duration (ms) |
foreground | App returns to the foreground | Session ID |
background | App goes to the background (the queue is flushed immediately) | Foreground duration |
screen_view | An Activity is shown, or trackScreen is called | Screen name |
crash (java / native) | Uncaught Java / Native exception | Type, message, stack, thread, foreground |
crash (anr) | Main thread blocked for more than 5 seconds | Main thread stack, foreground |
Every batch carries the device context: app version, channel, OS version, manufacturer, model, screen size, network, carrier and language. Location is resolved from the IP on the server; the visitor IP is stored on the server and is only available through the open API (MCP), not shown in the console.
Metrics
- Active users: distinct devices with events in the range. New users: devices first seen within the range.
- Launches: number of sessions; returning to the foreground after more than 30 seconds (configurable) in the background starts a new one. Launches per user = launches ÷ active users.
- Avg. session length: total foreground time per launch ÷ launches.
- Time on screen: time until the next screen view or background event in the same session, capped at 30 minutes.
- Crash rate = sessions with a crash (Java + Native) ÷ sessions; crash-free users = 1 − devices with a crash ÷ active devices. ANRs are counted separately.
- Crashes are grouped into issues by kind + exception class + top 5 stack frames (line numbers removed).
- Launch time: P50, P75 and P90 for cold, warm and hot starts separately.
- Retention: new users grouped by first-use date, share still active on day N.