Add umeng statistics to Android applications
Software and hardware environment
- Macbook Pro MGX 72
- Android Studio 1.3.2
- Genymotion Simulator
Preface
Umeng is a mobile application statistical analysis platform. It helps mobile app operators to collect statistics and analyze traffic sources, product retention data, user attributes, and behavior data, this allows product developers and operators to use data to make decisions on products, operations, and promotion strategies.
Integrate umeng SDK
First, go to the umeng official website http://www.umeng.com/register an account. After completing the registration, go to the management background to integrate the application of umeng statistics, as shown below:
After submission, assign the key to your application as follows:
Right-click the jar file in development Studio and select Add as library to complete the import.
Configure AndroidManifest. xml
Add the following permissions:
<uses-sdk android:minSdkVersion="4"></uses-sdk><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission><uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /><uses-permission android:name="android.permission.INTERNET"></uses-permission><uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
Enter the key and channel id. Only one channel can be added to a package, as shown below:
<Meta-data android: value = "Enter the key value allocated by umeng" android: name = "UMENG_APPKEY"/> <meta-data android: value = "Enter the channel name here, such as Wandoujia or 360 "android: name =" UMENG_CHANNEL "/>
Integration code
Call MobclickAgent. onResume (Context) in the onResume method of each Activity, and call MobclickAgent. onPause (Context) in the onPause method ). If there is an inheritance relationship between activities, do not add the onResume and onPause methods repeatedly. Otherwise, repeated statistics will appear, affecting the statistical results. If the App calls methods such as Process. kill or System. exit to kill a Process, call the MobclickAgent. onKillProcess (Context) method before killing the Process.
At this point, the basic functions have been integrated, and it is still very simple. Some of the subsequent advanced functions can be added as needed. The official documents are already detailed and will not be written here. If you are interested, go to umeng's official website to view them.
References
1. http://www.umeng.com/
2. http://dev.umeng.com/analytics/android-doc/integration