All Products
Search
Document Center

Quick start

Last Updated: May 25, 2021

About this task

The Social sharing component offers the feature of sharing to Weibo, WeChat, Alipay, QQ, DingTalk, text messages, and other channels. This component provides a unified API to the developers so that they do not need to cope with the differences among various SDK APIs. To add a share component to an Android client, you need to configure a project to determine the basic framework and add the SDK of the share component.

Before you begin

Before you add a sharing channel, make sure that you have registered an account on the official website of this channel. Some sample official sites of sharing channels are listed as follows:

Social sharing is supported in the native AAR mode, the mPaaS Inside mode, and the component-based mode.

  • If you want to connect the component to the mPaaS based on the native AAR mode, you need to first complete the prerequisites and the subsequent steps. For more information, see Add mPaaS to your project
  • If you want to connect the component to the mPaaS based on the mPaaS Inside mode, you need to first complete the mPaaS Inside access procedure.
  • If you want to connect the component to the mPaaS based on components, you need to first complete the Component-based access procedure.

Add the SDK

Native AAR mode

You can use the AAR Component Management (AAR) function to install the share component in your project. For more information, see AAR component management.

mPaaS Inside mode

Use the Component Management function to install the share component in your project.
For more information, see Manage component dependencies.

Component-based mode

In your Portal and Bundle projects, use the Component Management function to install the share component.
For more information, see Manage component dependencies.

Initialize mPaaS

In the native AAR or mPaaS Inside mode, you must initialize the mPaaS.
Add the following code to the Application class:

 
  1. public class MyApplication extends Application {
  2. @Override
  3. protected void attachBaseContext(Context base) {
  4. super.attachBaseContext(base);
  5. // Initialize callback settings for mPaaS.
  6. QuinoxlessFramework.setup(this, new IInitCallback() {
  7. @Override
  8. public void onPostInit() {
  9. // This callback indicates that mPaaS has been initialized, and mPaaS-related calls can be made in this callback.
  10. }
  11. });
  12. }
  13. @Override
  14. public void onCreate() {
  15. super.onCreate();
  16. // Initialize mPaaS.
  17. QuinoxlessFramework.init();
  18. }
  19. }

Use the social sharing SDK on different platforms

This topic describes how to use the social sharing SDK in the baseline version 10.1.32 and later based on the official demo of Social sharing.

Share to WeChat

You need to manually create an Activity with a specific path and name to receive callback events for sharing to WeChat. This Activity inherits from DefaultWXEntryActivity. The path is package_name.wxapi.WXEntryActivity, where package_name is the package name of the application.

Note: The path and the ‘Activity’ name must be correctly specified. Otherwise, the application will fail to receive any callback.

In the following example, the package name is com.mpaas.demo.

 
  1. package com.mpaas.demo.wxapi;
  2. import com.alipay.android.shareassist.DefaultWXEntryActivity;
  3. public class WXEntryActivity extends DefaultWXEntryActivity {
  4. }

Register for the Activity in AndroidManifest.xml:

 
  1. <application>
  2. ···
  3. <activity android:name="com.mpaas.demo.wxapi.WXEntryActivity"
  4. android:exported="true"
  5. android:launchMode="singleTop"></activity>
  6. ···
  7. </application>
Note: When you set the WeChat share icon, make sure that the icon size does not exceed 32 KB. Otherwise, the WeChat sharing may fail. The SDK for Android needs to be validated. If the WeChat share icon exceeds 32 KB, then the default Alipay icon will be used instead.

Share to QQ and QZone

You need to register for the Activity required for sharing to QQ in AndroidManifest.xml. Otherwise, you will fail to use the features of sharing to QQ and QZone and the callback feature.

Note:
  • If the QQ share ID that you write in the ‘AndroidManifest.xml’ file is different from the QQ share ID registered in the code, a callback error will occur during the share. And the ‘onException’ callback is called even the share is successful. Therefore, you need to check the QQ share ID carefully.
  • Enter the corresponding QQ share ID in data android:scheme. The ID format is ‘tencent’ immediately followed by a QQ ID, which is tencent+QQID. Note that + is not included in the QQ share ID. You need to register for this ID on Tencent Open Platform. In the following example, the QQ ID is ‘1104122330’.

 
  1. ```xml
  2. <application>
  3. ···
  4. <activity
  5. android:name="com.tencent.connect.common.AssistActivity"
  6. android:configChanges="orientation|keyboardHidden|screenSize"
  7. android:screenOrientation="portrait"
  8. android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
  9. <activity
  10. android:name="com.tencent.tauth.AuthActivity"
  11. android:launchMode="singleTask"
  12. android:noHistory="true">
  13. <intent-filter>
  14. <action android:name="android.intent.action.VIEW"/>
  15. <category android:name="android.intent.category.DEFAULT"/>
  16. <category android:name="android.intent.category.BROWSABLE"/>
  17. <data android:scheme="tencent1104122330"/>
  18. </intent-filter>
  19. </activity>
  20. ···
  21. </application>
  22. ```

Share to Weibo

Make sure that the application signature, the package name, and the share ID are the same as those registered on Weibo Open Platform. Otherwise, a sharing failure will occur. If a sharing failure occurs due to this inconsistency issue, the share component triggers the sharing success callback onComplete rather than the sharing exception callback onException. This defect comes with the Weibo SDK. And the same issue occurs in the official demo of the Weibo SDK.