This topic describes how to quickly integrate the Social Share SDK.
About this task
The Social Share component enables you to share content through various channels, such as Weibo, WeChat, Alipay, QQ, DingTalk, and text messages. It provides a unified interface for developers, so you do not have to manage the differences between each SDK. To integrate the Share component into an Android client, you must configure your project and add the share component SDK.
Prerequisites
Before you integrate with a channel, you must apply for an account on its official website. Examples include the following:
Social Share supports two connection types: native AAR and component-based.
If you use the native AAR method, you must first complete the prerequisites and follow-up steps described in Add mPaaS to your project.
If you use the component-based method, you must first complete the Component-based integration process.
Add the SDK
Native AAR method
For more information, see AAR Component Management. Use Component Management (AAR) to install the Share component in your project.
Component-based method
In your Portal and Bundle projects, use Component Management to install the Share component. For more information, see Manage component dependencies.
Initialize mPaaS
If you use the native AAR method, you must initialize mPaaS by adding the following code to your Application:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize mPaaS
MP.init(this);
}
}For more information, see Initialize mPaaS.
Use the Share SDK for each platform
This topic uses the official Social Share demo to demonstrate how to use the Social Share SDK in baselines 10.1.32 and later.
WeChat Share
You must manually create an Activity to receive callback events from WeChat Share. This Activity must have a specific path and name. It must inherit from DefaultWXEntryActivity, and its path must be package_name.wxapi.WXEntryActivity, where package_name is your application's package name.
The path and Activity name must be exact. Otherwise, you will not receive callbacks.
In this 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 this Activity in AndroidManifest.xml:
<application>
···
<activity android:name="com.mpaas.demo.wxapi.WXEntryActivity"
android:exported="true"
android:launchMode="singleTop">
</activity>
···
</application>When you set the share icon, make sure its size does not exceed 32 KB. If it does, WeChat sharing might fail. The Android SDK currently checks the icon size. If an icon is larger than 32 KB, the SDK replaces it with the default Alipay icon.
QQ and QZone Share
You must register the required Activity for QQ sharing in AndroidManifest.xml. Otherwise, the share and callback features for QQ and QZone will not work.
If the QQ Share ID that you enter in
AndroidManifest.xmldoes not match the one registered in your code, QQ Share callbacks will be disrupted. TheonExceptioncallback is triggered even if the sharing is successful. Ensure that the IDs match.In
data android:scheme, you must enter the corresponding QQ Share ID. The format istencentfollowed by your QQ ID. You must apply for this ID on the 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>Weibo Share
Ensure that your application signature, package name, and Share ID match the information registered on the Weibo Open Platform. A mismatch will cause sharing to fail. If sharing fails due to a mismatch, the share component's callback triggers onComplete instead of onException. This is a known bug in the Weibo SDK that also occurs in the official Weibo SDK demo.
Related links
For code samples, usage instructions, and notes, see Get code samples.
Related API documentation: