The new version of UmENG does not need to configure multiple channels and the documentation is simpler. Friend alliance document, import into the document can be. The general steps are as follows:

  • 1. Create an application on Umeng and obtain the AppKey
    1. Integrate SDK. Automatic integration is recommended

Maven dependency Configuration

Add the new Maven repository address of the [Friendly +] SDK to the buildScript and AllProjects sections of the project build.gradle configuration script. The diagram below.

Code:

Copy code to clipboard

  1. maven { url 'https://dl.bintray.com/umsdk/release' }

Add the basic component library and statistical SDK library dependencies to the Dependencies section of the build.gradle configuration script of the project App.

Code:

Copy code to clipboard

  1. The compile 'com. Umeng. Umsdk: analytics: 8.0.0'
  2. The compile 'com. Umeng. Umsdk: common: 2.0.0'

In the Android Studio 3.1 or later development environment, specifying “latest.integration” may cause the download library to timeout. In this case, you need to specify the version.

    1. Integration configuration, mainly some permissions and confusion
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
Copy the code
-keep class com.umeng.** {*; } -keepclassmembers class * { public <init> (org.json.JSONObject); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }Copy the code
    1. Select the functions you want to integrate, you can choose, the main integration channels and statistical functions below
// Add the channel name, upload it to umconfigure. init(this,"AppKey friends union",
            Utils.getUMChannelName(this), UMConfigure.DEVICE_TYPE_PHONE, "")
        UMConfigure.setLogEnabled(true)
Copy the code

The method of obtaining channels is related to channels as follows:

/** * get the channel name ** @param CTXreturnPublic static String getUMChannelName(Context CTX) {public static String getUMChannelName(Context CTX) {if (ctx == null) {
            return null;
        }
        String channelName = null;
        try {
            PackageManager packageManager = ctx.getPackageManager();
            if(packageManager ! = null) {ApplicationInfo not ActivityInfo because the meta data set is in the application tag, not in the activity tag. So use ApplicationInfo ApplicationInfo ApplicationInfo = packageManager. GetApplicationInfo (CTX) getPackageName (), PackageManager.GET_META_DATA);if(applicationInfo ! = null) {if(applicationInfo.metaData ! = null) { channelName = applicationInfo.metaData.getString("UMENG_CHANNEL");
                    }
                }
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return channelName;
    }
Copy the code
  • 5. Call mobClickAgent.onResume (context) in the onResume method of each Activity in the App and mobClickAgent.onPause (context) in the onPause method.
@Override
public void onResume() {
    super.onResume();
    MobclickAgent.onResume(this);
}
@Override
public void onPause() { super.onPause(); MobclickAgent.onPause(this); } to note: Make sure that the MobclickAgent. OnResume and onPause methods are called in all activities (note that if you are in AUTO page collection mode, The MobclickAgent. OnResume and onPause methods cannot be called in any Activity, as described in the collecting section of the next page.) These calls do not block the main thread of the application and do not affect application performance. Note: If your activities have an inheritance or control relationship, do not add nPause and nResume methods to both parent and child activities. This will result in repeated statistics and an abnormally high number of starts. (for example, when using TabHost, TabActivity, ActivityGroup). When an application runs in the background for more than 30 seconds (the default) and then returns to the foreground, it is considered to have two separate sessions, such as when the user returns to the home, or enters another application, and then returns to the previous application after a period of time. That is, it is considered two separate sessions.Copy the code
  • 6. Hardening configuration signatures

    Configure multiple channels, which need to configure what, statistical platform here to choose Umeng, channel number customized

    Set the input path in the Settings, upload files in the application hardening, you can complete the hardening, and finally get a package without channels and other channels. All packages need to be re-signed to be installed. You can select one or more APK files at a time to sign the APK file. Channel packaging this one, set up a lot of channels, you can directly choose channel packaging, played out of all the packages can be signed again.

    To the bestTheir Allies documentTo be less prone to error.demo