MobTech ShareSDK Android Quick Integration

Time:2022-9-22

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

Preparation before integration

Register an account
1. Before using MobSDK, you need to register a developer account on the MobTech official website and obtain the AppKey and AppSecret provided by MobTech. For details, please refer toClick to view the registration process

2. You need to apply for the key of a third-party platform, you can click for detailsView the registration process

ShareSDK flow chart

add configuration
Register MobSDK in project Gradle file

buildscript {
    repositories {
        // 1. Add MobSDK Maven address
        maven {
            url "https://mvn.mob.com/android"
        }
        ...
    }
    dependencies {
        ...
        // 2. Register MobSDK
        classpath "com.mob.sdk:MobSDK:2018.0319.1724"
    }
}

Add plugins and extensions to the Gradle file of the project App Module
Among them, devInfo is the application information from the social platform. For the complete parameters of each platform, please click here for details;

For specific field parameter descriptions, etc., clickSee details here

apply plugin: 'com.mob.sdk'
MobSDK {
    appKey "your appkey"
    appSecret "your appsecrt"
    ShareSDK {
        devInfo {
            Wechat {
                appId "wx4868b35061f87885"
                appSecret "64020361b8ec4c99936c0e3999a9f249"
                userName "gh_afb25ac019c9"
                path "pages/index/index.html?id=1"
                withShareTicket true
                miniprogramType 2
            }
            WechatMoments {
                appId "wx4868b35061f87885"
                appSecret "64020361b8ec4c99936c0e3999a9f249"
            }
            .......
        }
    }
  }

Add code in gradle.properties
MobSDK.spEdition=FP

interface call

Returns the user privacy authorization result (submitPolicyGrantResult)
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 is installed cold for the first time and after obtaining the user's authorization to read your Privacy Policy, call MobSDK.submitPolicyGrantResult to return the privacy agreement authorization result.
On the other hand, if the user does not agree with the authorization of your App's "Privacy Policy", he cannot call MobSDK.submitPolicyGrantResult to return the privacy agreement authorization result.
Please refer to the relevant privacy statementCompliance Guidelines

/**
 * com.mob.MobSDK.class
 * Return the result of user privacy authorization
 * @param isGranted whether the user agrees to the privacy agreement
 */  
public static void submitPolicyGrantResult(boolean isGranted)

sample code
The calling location can be specified by the developer, and only needs to be called before using the SDK function. It is strongly recommended that the developer call after the end user clicks the consent button in the application privacy agreement pop-up window.

MobSDK.submitPolicyGrantResult(true);

Share interface call (share)

//cn.sharesdk.framework
/**
 * share separately
 * @param params share parameters
 */  
public void share(Platform.ShareParams params)

sample code
The following uses QQ as an example to illustrate how to use this method to realize the sharing function.

ShareParams sp = new ShareParams();
sp.setTitle("Test share title");
// hyperlink to title
sp.setTitleUrl("https://sharesdk.cn"); 
sp.setText("Test shared text");
sp.setImageUrl("http://www.someserver.com/test image network address.jpg");
Platform qq = ShareSDK.getPlatform (QQ.NAME);
// Set the sharing event callback (Note: The callback cannot be guaranteed to be called on the main thread, and UI operations cannot be directly processed in it)
qq.setPlatformActionListener (new PlatformActionListener() {
    public void onError(Platform arg0, int arg1, Throwable arg2) {
        // Failed callback, arg: platform object, arg1: indicates the current action (9 indicates sharing), arg2: exception information
    }
    public void onComplete(Platform arg0, int arg1, HashMap arg2) {
        // Share successful callback
    }
    public void onCancel(Platform arg0, int arg1) {
        // cancel the share callback
    }
});
// execute share
qq.share(sp);