All Products
Search
Document Center

Mobile Platform as a Service:Quick start

Last Updated:Nov 17, 2023

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 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 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.

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 mode, you must initialize the mPaaS.

Add the following code to the Application class:

public class MyApplication extends Application {
    
    @Override
    public void onCreate() {
        super.onCreate();
        // mPaaS initialization
        MP.init(this);    
    }
}

For more details, see Initialize mPaaS.

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.

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

Register for the Activity in AndroidManifest.xml:

<application>
      ···
      <activity android:name="com.mpaas.demo.wxapi.WXEntryActivity"
      android:exported="true"
      android:launchMode="singleTop">
			</activity>
      ···
</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’.

<application>
      ···
      <activity
            android:name="com.tencent.connect.common.AssistActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
      <activity
            android:name="com.tencent.tauth.AuthActivity"
            android:launchMode="singleTask"
            android:exported="true"
            android:noHistory="true">
            <intent-filter>
                  <action android:name="android.intent.action.VIEW"/>
                  <category android:name="android.intent.category.DEFAULT"/>
                  <category android:name="android.intent.category.BROWSABLE"/>
                  <data android:scheme="tencent1104122330"/>
            </intent-filter>
      </activity>
      ···
</application>

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.