Development tool: DevEco Studio Integration method: Gradle online integration

Preparation before integration

Registering an account <br>Before using ShareSDK, you need to register a developer account on the MobTech official website and obtain the AppKey and AppSecret provided by Mob. For details, you can click to view the registration process

Social Platform Registration <br>Before using ShareSDK, you need to register, review and obtain a Key on the third-party social platform you need to use. Due to the different requirements of different social platforms, it will not be displayed here.

Add configuration <br>Register MobSDK in project Gradle file

 buildscript {
    repositories {
        // 1.添加MobSDK Maven地址
        maven {
            url "https://mvn.mob.com/android"
        }
        ...
    }
    dependencies {
        ...
        // 2.注册MobSDK
        classpath 'com.mob.hossdk:MobSDK:+'
    }
}

image.png

Add plugins and extensions to the Gradle file of the project App Module

 apply plugin: 'com.mob.hossdk'
MobSDK {
    appKey "xxxxxx"
    appSecret "xxxxxxxxxxxx"
    ShareSDK {
        devInfo {
            //目前只支持微信好友、微信朋友圈、微信收藏、QQ、QQ空间、新浪微博
            Wechat {
                id 4
                sortId 4
                appId "xxxxxx"
                appSecret "xxxxxxxxxxxx"
                withShareTicket true
                bypassApproval false
                enable true
            }
            WechatMoments {
                id 5
                sortId 5
                appId "xxxxxx"
                appSecret "xxxxxxxxxxxx"
                bypassApproval false
                enable true
            }
                WechatFavorite {
                id 6
                sortId 6
                appId "xxxxxx"
                appSecret "xxxxxxxxxxxx"
                bypassApproval false
                enable true
            }
                QQ {
                id 7
                sortId 7
                appId "xxxxxx"
                appKey "xxxxxxxxxxxx"
                shareByAppClient true
                bypassApproval false
                enable true
            }
        }
    }
}

image.png

Other configuration items
devInfo under ShareSDK currently only supports:
image.png

Returns the user privacy authorization result (submitPolicyGrantResult)

 //MobSDK.class
/**
 * 回传用户隐私授权结果
 * @param isGranted     用户是否同意隐私协议
 * @param callback      接口执行结果,可为null
 */  
public static void submitPolicyGrantResult(boolean isGranted, com.mob.OperationCallback callback)

The developer can specify the calling location of the sample code by himself, just call it before using the SDK function.

 MobSDK.submitPolicyGrantResult(true, null);

API interface and sample code

There is no difference between the Hongmeng version API interface of ShareSDK and the native Android API interface. You can refer to the link for testing. The following example uses WeChat to share url pictures:

 Platform platform = ShareSDK.getPlatform(Wechat.NAME);
Platform.ShareParams shareParams = new Platform.ShareParams();
shareParams.setImageUrl("https://www.tfkjy.cn/scskx/image/20200611/ae7a53f681e538ea4e132f0d9419ccdc.jpg?download=0");
shareParams.setShareType(Platform.SHARE_IMAGE);
platform.setPlatformActionListener(null);
platform.share(shareParams);

Demo project

Link


中关村科金
136 声望13 粉丝

北京中关村科金技术有限公司(简称“中关村科金”)是国内领先的对话式AI技术解决方案提供商,成立于2014年,注册资本14亿元,总部位于北京,在上海、重庆、深圳、杭州、成都等地设有分支机构,公司规模近千人,其...