Preparations
Before integrating DingTalk sharing on Android, complete the following preparations:- Set up the Android development environment.
- Download the Android SDK.
- Install DingTalk client version 2.7.0 or later.
Step 1: Integrate DingTalk Sharing
- Sign in to the Developer Console, and then go to the app details page.
- On the app details page, click DingTalk Sign-in and Sharing to open the sign-in and sharing page.
- In the Integrate Sharing section, click Edit on the right.
- Turn on Android Sharing, enter the Android Package Name and Android Signature in order, and then click Save. Note For how to obtain the signature, see Signature Method.
Step 2: Set Up the Development Environment
Set up the development environment using either of the following methods.-
Method 1: Gradle dependency
Add
compile 'com.alibaba.android:ddsharesdk:1.1.0'to thedependenciesin the module’sbuild.gradle. -
Method 2: Import the JAR file directly
- Create an Android project named DDShareDemo, create a libs directory in the project, and copy the downloaded JAR file to that directory, as shown below:
- Add the JAR file in the libs directory to the project dependencies.
Step 3: Use the SDK in Your Code
If your app needs to receive requests sent by DingTalk, or receive responses to requests sent to DingTalk, perform the following steps:-
Create a
ddsharedirectory under the corresponding directory of your package name. Then add the exported attribute in theAndroidManifestfile and set it to true. -
Implement the IDDAPIEventHandler interface. DingTalk’s response is returned to the onResp method through a callback.
The following is sample code for the onResp method:
-
In the DDShareActivity class, pass the received intent and the object that implements the IDDAPIEventHandler interface to the handleIntent method of the IDDShareApi interface. Then, when your app requests DingTalk’s response, DingTalk returns it by calling the onResp method.
-
Determine whether the current device supports sharing.
-
Determine whether DingTalk is installed on the current device.
-
Determine whether the current device supports sharing to DingTalk (DingTalk is installed and the DingTalk version supports sharing).
-
Determine whether DingTalk is installed on the current device.
- Supported share types. Text, Image, Link, and the special Alipay red packet type are supported. For specific usage, see the downloaded Android SDK samples.