Mob social sharing integrated ShareSDK

How to integrate ShareSDk into the project when the project has already integrated SMSSDK, you need to import ShareSDk by creating a module, the main content is as follows:

1. Download ShareSDK

2. Introduce ShareSDK

3. Create MainLibs Module

4. Create OneKeyShare Module

5. Introduce Module in the project

6. Configure permissions

7. Configure Application

8. Enable ShareSDK

Download ShareSDk

Official website download address: ShareSDK , select the platform to share when downloading, as shown in the figure below:

The downloaded ShareSDk is decompressed as follows, the version downloaded here is ShareSDK-Android-3.0.0, as shown in the figure below:

Introduce ShareSDK

First, copy the ShareSDK.xml file in the ShareSDk to the assets directory in the project. Here, the ShareSDk is introduced by importing a module. The following two Libs are mainly imported into the ShareSDK, as shown in the following figure:

The following demonstrates the process of creating a Module:

Create the MainLibs Module

1. Create an Android Library in the newly created project, and click the link to demonstrate:

2. Delete all the files under main in the newly created Library, as well as the java and res folders and the AndroidManifest.xml file, as shown in the figure below:

3. Copy res, AndroidMainfest.xml, and libs (jar inside) in MainLibs to be imported to the corresponding folder, as shown in the figure below:

Import the structure in mainLibs as follows:

At this point, the module is created, and the sharing page provided by ShareSDK is used here, so OneKeyShare needs to be introduced.

Create OneKeyShare Module

The process of creating a Module is the same as above. Note that there is an additional src, which contains the java file to be used, so it must be referenced, as shown in the following figure:

Just copy the src folder to the main. If there is no error after the build, it means that the Module was created successfully. The following depends on the dependency relationship as the corresponding Module.

Introduce Module in the project

Here, OnKeyShareLibs depends on MainLibs, and only the app needs to depend on OnkeyShareLibs. Here is a demonstration of how OnKeyShareLibs depends on MainLibs. Click the link to demonstrate:

Then, the app depends on OnKeyShareLibs in the same way.

Configure permissions

The SMSSDK has been configured here before, just add the missing permissions. The following is all the permissions required to integrate the SMSSDK and ShareSDK at the same time, as follows:

   <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

Configure Application

If SMSSDK has been configured before, then MobUIShell has been configured, just add the missing IntentFilter, and integrate SMSSDK and ShareSDK to share MobUIShell, as follows:

        <data android:scheme="tencent100371282" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />


If your project integrates WeChat or WeChat Moments, please check the package path in the AndroidManifest.xml configuration file. You need to create a wxapi directory under the package directory and then place WXEntryActivity. If there is no such activity, the callback will check whether there is such an activity after WeChat sharing, and if there is no such activity, an error will be reported:

    android:screenOrientation="portrait" />

For details, please refer to: Android ShareSDK complete integration documentation

Enable SDK s

via AndroidManifest.xml

Add the following properties under the Application node:


Add meta parameters under the Application tag:

<!-- pass AndroidManifest configuration AppKey with AppSecret´╝îIf you choose to configure by code, you do not need to configure the following meta-data -->
<meta-data android:name="Mob-AppKey" android:value="yours AppKey"/>
<meta-data android:name="Mob-AppSecret" android:value="yours AppSecret"/>

code configuration

// Register your AppKey and AppSecret via code
MobSDK.init(context, "yours AppKey", "yours AppSecret");

Of the above two methods, only one of them can be used to initialize ShareSDK.

Call the sharing interface

private void showShare() {
     OnekeyShare oks = new OnekeyShare();
     //Close sso authorization
     // title, used by Evernote, Email, Message, WeChat, Renren and Qzone
     // titleUrl is the web link of the title, only used in Renren and Qzone
     // text is the shared text, all platforms require this field
     oks.setText("I am sharing text");
     // imagePath is the local path of the image, and platforms other than LinkedIn support this parameter
     oks.setImagePath("/sdcard/test.jpg");//Make sure this picture exists under SDcard
     // The url is only used in WeChat (including friends and circle of friends)
     // comment is my comment on this sharing, it is only used in Renren and Qzone
     oks.setComment("I am testing comment text");
     // site is the name of the website sharing this content, it is only used in Qzone
     // siteUrl is the website address for sharing this content, it is only used in Qzone

    // Start sharing GUI;

Tags: Java Front-end Algorithm Android Operation & Maintenance developer

Posted by spooke2k on Tue, 20 Dec 2022 18:07:07 +1030