This information helps you implement the Android library and collect lifecycle metrics, such as launches, upgrades, sessions, engaged users, and so on.
Important: To download the SDK, you must use Android 2.2 or later.
-
Complete the steps in the following sections to set up a development report suite and download a pre-populated version of the configuration file:
-
Download and unzip the
[Your_App_Name_]AdobeMobileLibrary-4.*-Android.zip
file and verify that the following software components exist:-
adobeMobileLibrary.jar
, which is the library that will be used with Android devices and simulators. -
ADBMobileConfig.json
, which is the SDK configuration file that is customized for your app.
Important: If you download the SDK outside the Adobe Mobile services UI, the
ADBMobileConfig.json
file must be manually configured. If you are new to Analytics and the Mobile SDK, and you want to set up a development report suite and download a pre-populated version of the configuration file, see Before You Start. -
IntelliJ IDEA project
To add the SDK and config file to your project:
-
Add the
ADBMobileConfig.json
file to theassets
folder in your project. -
Right click your project in the project navigation panel.
-
Select Open Module Settings.
-
Under Project Settings, select Libraries.
-
Click the + icon to add a new library.
-
Select Java and navigate to the
adobeMobileLibrary.jar
file. -
Select the modules where you plan to use the mobile library.
-
Click Apply and OK to close the Module Settings window.
Eclipse project
To add the SDK and config file to your project:
- Add the
ADBMobileConfig.json
file to theassets
folder in your project. - In Eclipse IDE, right-click the project name.
- Click Build Path > Add External Archives.
- Select
adobeMobileLibrary.jar
. - Click Open.
- Right-click the project again and select Build Path > Configure Build Path.
- On the Order and Export tab, ensure that
adobeMobileLibrary.jar
is selected.
The AppMeasurement Library requires the following permissions to send data and record offline tracking calls:
INTERNET
ACCESS_NETWORK_STATE
To add these permissions, add the following lines to your AndroidManifest.xml
file, which is located in the application project directory:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
The following code should be added in the onCreate
method of your main activity:
@Override
public void onCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState)
setContentView(R.layout.main);
Config.setContext(this.getApplicationContext());
}
After you enable lifecycle, each time your app is launched, one hit is sent to measure launches, upgrades, sessions, engaged users, and many other metrics. For more information, see Lifecycle Metrics.
Complete the following steps in each activity of your application:
-
Import the library:
import com.adobe.mobile.*;
-
In the
onResume
function, start the lifecycle data collection:@Override public void onResume() { Config.collectLifecycleData(this); // -or- Config.collectLifecycleData(this, contextData); }
-
In the
onPause
function, pause the lifecycle data collection:@Override public void onPause() { Config.pauseCollectingLifecycleData(); }
Important: You must add these calls to every activity to ensure accurate crash reporting. For more information, see Track App Crashes.
To include additional data with lifecycle metric calls, pass an additional parameter to collectLifecycleData
that contains context data:
@Override
public void onResume() {
HashMap<String, Object> contextData = new HashMap<String, Object>();
contextData.put("myapp.category", "Game");
Config.collectLifecycleData(this, contextData);
}
Additional context data values that are sent with collectLifecycleData
must be mapped to custom variables in Adobe Mobile services:
Other lifecycle metrics are collected automatically. For more information, see Lifecycle Metrics.
Complete the following tasks: