MobPush: Android SDK Integration Guide

Development tool: Android Studio
Integration method: Gradle online integration
Android version support: minSdkVersion 19

Integration preparation

Register an account

Before using PushSDK, you need to register a developer account on the MobTech official website and obtain the AppKey and AppSecret provided by MobTech. For details, please click to view the registration processlink

MobPush background configuration

After registering a MobTech account, you need to configure relevant information in the MobTech background. For details, you can click to view the specific configuration informationlink

MobPush flow chart

picture

Integration configuration

Configure the SDK address

The code base configuration method of Android Studio varies with different versions of the Gradle plugin. Please select the corresponding configuration method according to the version of your current Gradle plugin.
[Version 7.0 and above]
1. Open the project-level "settings.gradle" file, configure the address of the Maven warehouse, and pay attention to modify the repositoriesMode to RepositoriesMode.PREFER_SETTINGS.

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven {
            url "https://mvn.mob.com/android"
        }
    }
}
dependencyResolutionManagement {
    // repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
        maven {
            url "https://mvn.mob.com/android"
        }
    }
}

2. Open the Android Studio project-level build.gradle file and configure the MobSDK plug-in address

buildscript {
    dependencies {
        // 增加MobSDK插件配置
        classpath "com.mob.sdk:MobSDK2:+"
        // 增加google services插件配置,用于集成FCM,不集成FCM可不配置
        classpath 'com.google.gms:google-services:4.3.14'
    }
}

plugins {
    id 'com.android.application' version 'x.x.x' apply false
    id 'com.android.library' version 'x.x.x' apply false
}

【Version below 7.0】

1. Open the Android Studio project-level build.gradle file.
2. Configure the maven warehouse address in allprojects -> repositories.

allprojects {
    repositories {
        maven {
            url "https://mvn.mob.com/android"
        }
    }
}

3. Configure the maven warehouse address in buildscript->repositories.

buildscript {
    repositories {
        maven {
            url "https://mvn.mob.com/android"
        }
    }
}

4. Configure the AppGallery Connect plug-in address in buildscript->dependencies

buildscript {
    dependencies {
        //增加MobSDK插件配置
        classpath "com.mob.sdk:MobSDK2:+"
    }
}
add dependencies

1. Open the application-level build.gradle file.
2. Add mob plugin configuration. Please choose according to the actual situation:

  • Method 1: Add the following configuration in the next line of the "com.android.application" plugin.
apply plugin: 'com.mob.sdk'
  • Method 2: Add the following configuration in "plugins".
plugins {
    id 'com.android.application'
    id 'com.mob.sdk'
}

3. Add the mob configuration code at the end of the file

MobSDK {
    appKey "替换为MobTech官方申请的appkey"
    appSecret "替换为MobTech官方申请的appkey对应的appSecret"
    MobPush {}
}
Configuration ID

Add code in gradle.properties

MobSDK.spEdition=FP
Google Play version

If your app needs to be listed on the Google store, please be sure to use the Google Play version.
Add code in gradle.properties, if MobSDK.spEdition=FP related configuration has been added, just modify FP to GPP.

MobSDK.spEdition=GPP
Configure obfuscated code

Add the following obfuscated code to the project

-keep class com.mob.**{*;}
-dontwarn com.mob.**

Privacy authorization

In order to ensure that your app can meet the relevant compliance requirements of the Ministry of Industry and Information Technology after integrating MobSDK, you should ensure that the app installation is cold-started for the first time and after obtaining authorization from the user to read your "Privacy Policy", call MobSDK.submitPolicyGrantResult to return the privacy agreement authorization result.

Conversely, if the user does not agree to your app's "Privacy Policy" authorization, you cannot call MobSDK.submitPolicyGrantResult to return the privacy agreement authorization result. Please refer to the Compliance Guidelineslink

/**
 * com.mob.MobSDK.class
 * 回传用户隐私授权结果
 * @param isGranted     用户是否同意隐私协议
 */  
public static void submitPolicyGrantResult(boolean isGranted)

Sample code note: The developer can specify the call location by himself, and only needs to call it before using the SDK function. It is strongly recommended that the developer call it after the end user clicks the consent button in the application privacy agreement pop-up window.

MobSDK.submitPolicyGrantResult(true);

log debugging

Please add the above configuration in the AndroidManifest.xml file, and you can view the relevant logs with TAG MobPushLog in the log console:

<meta-data
      android:name="com.mob.mobpush.debugLevel"
      android:value="4" />

picture

test confirmation

  • Confirm that the resource package has been pulled through gradle. The package name is: "com.mob:MobSupportV1:xxxxxxxxx"; "com.mob:MobCoreULT:xxxxxxxxx"; "com.mob:MobGUIULT:xxxxxxxxx@aar"; "com.mob :PushSDK:xxx@aar"
  • Confirm that the AppKey has been correctly written into the Androidmanifest.xml (check the Androidmanifest in app-debug.apk for confirmation)
  • Confirm that the test mobile phone has called the privacy protocol interface and uploaded true: MobSDK.submitPolicyGrantResult(true);
  • Confirm that the test mobile phone (or emulator) has successfully connected to the network + client calls, do not use network proxy and VPN, if everything is normal, there should be log information of MobPushLog after starting the project, refer to the tag as follows
    picture

Advanced function

Registration ID instructions

Obtain: For obtaining the Registration ID, please click to view the MobPushSDK API use link

Instructions for use: Since all forms of MobPush pushes will eventually be transformed into pushes for Registration IDs, Registration IDs are a necessary identification for pushes and associated user information. At the same time, in order to facilitate online customers to provide accurate information and reduce communication costs, we recommend that you store and record the Registration ID after completing the SDK integration. When troubleshooting, you can feed back the Registration ID and task ID together, which can speed up the troubleshooting process

Guess you like

Origin blog.csdn.net/apkkkk/article/details/131762790