Android SHARESDK fast Sharing _android

Source: Internet
Author: User

First step: Get SHARESDK

In order to integrate SHARESDK, you first need to register and create an application to SHARESDK official website, obtain SHARESDK appkey, then download the SDK package on the download page of the SDK, and after decompression, you can get the directory structure of the following diagram:

Sharesdk in the "Sharesdk for Android" directory, "Libs" In this directory contains "Mainlibs" and "Onekeyshare", respectively, SHARESDK's core library and the "fast-sharing" source library, and documentation is also " SHARESDK for Android directory, be sure to read carefully before you integrate SHARESDK. The "Sharesdk for Android Apidoc" includes Javadoc for Mainlibs and Onekeyshare for developers to review. "Sharesdk for Android Sample" contains Sharesdk's feature demo code and APK file, the Sample source of Javadoc in. "Sharesdk for Android Services" contains the SHARESDK "plugin service" that has been released for the time being, we only provide "comment and praise" services, and we have already provided a dependency library, sample code, Javadoc, and apk files for this plug-in service in the package.

Step Two: Import sharesdk

SHARESDK Integration mode:

1. Direct copy jar package to target Project Libs directory

The way to directly copy jars and resources, you can refer to SHARESDK's sample project. With the method of duplicating jars, you need to replicate the mainlibs/res picture and strings in addition to the jars in the mainlibs/libs, otherwise there will be a problem when the resource is not found in the authorization. And if your project also integrates fast sharing, you also need to replicate the source code in ONEKEYSHARE/SRC, onekeyshare/res resources, if your project does not have android-support-v4 jar need to onekeyshare/ Libs under the ANDROID-SUPPORT-V4 jar into your project.

2, quickly build the project

Because of the hassle of directly replicating jar packages and resource integration, SHARESDK provides fast-integrated programs that can be double-clicked directly under Windows, and can be overwritten by copying files from the destination directory to your project. Greatly simplifies the operational steps of the integrated approach of "directly replicating jars and resources". For your project is just developed or want to write a demo test sharesdk feature, you can use this method to quickly integrate

Step Three: Add application information

There are three different ways

The first: configured in the SHARESDK application management background, using this method to initialize the SHARESDK.INITSDK (context, the Appkey that your application returns at SHARESDK registration). If you change the registration information later, you can change it directly from the web without republishing the new version for updating. (highest priority).

The second is to configure the "Setplatformdevinfo (String, hashmap<string, Object>)" method by code, which requires calling Sharesdk.init (context, The Appkey method that your application returns at SHARESDK registration is initialized. (in priority).

The third: the "assets/sharesdk.xml" file to configure, the secondary method will be in plaintext, but this is the easiest way. (lowest priority).

These three ways developers can choose for themselves, but these three settings are different: the first way to achieve "Dynamic Configuration Application Information" function, but once out of the network, SHARESDK may not work; The third is the lowest priority, but it is the most convenient, centralized The final use of code settings is the most flexible way, the second way developers can write dead in the code application information, but also through the private protocol, from their own server to dynamically obtain application registration information, its priority between the first and second. Using Sharesdk.xml to configure registration information

<SHARESDK appkey= "Fill in the Appkey"/> <sinaweibo sortid= "that you registered on SHARESDK the 
platform in your share list, integral type, the larger the number, the 
more. Appkey= "Fill in the Appkey" appsecret= "that you registered on Sina Weibo to fill in the 
appsecret" 
id= "custom field that you registered on Sina Weibo, integral type, for the identifier 
for this platform in your project. Redirecturl= "Fill out the RedirectURL" sharebyappclient= "you registered on Sina Weibo to 
share with clients" 

Sharesdk.xml stores data in XML format, each platform is a block, in addition to social platform, developers in SHARESDK registered application Appkey need to fill in the Block "SHARESDK", if this appkey is not the developer's own Appkey, The statistics that will be applied back to the SHARESDK in the future are not correct. Sharesdk each platform has sortid, IDs, enable four fields, in addition to fields (such as Sina Weibo Appkey, Appsecret, RedirectURL, Sharebyappclient and other fields) need to be registered on the target platform to get the application, please fill out the data of these fields correctly, otherwise SHARESDK cannot complete the authorization, then other operations will also be unable to perform.

Code Configuration Registration Information sample (demo to initialize Sina Weibo configuration information) because each sharing platform can set different configuration information, specific sharing platform need to set which configuration information please refer to the Sharesdk.xml configuration file in sample

SHARESDK.INITSDK (Context, "Appkey that your application returns at the time of SHARESDK registration"); 
hashmap<string,object> HashMap = new hashmap<string, object> (); 
Hashmap.put ("Id", "1"); 
Hashmap.put ("SortID", "1"); 
Hashmap.put ("Appkey", "568898243"); 
Hashmap.put ("Appsecret", "38a4f8204cc784f81f9f0daaf31e02e3"); 
Hashmap.put ("RedirectURL", "http://www.sharesdk.cn"); 
Hashmap.put ("Sharebyappclient", "true"); 
Hashmap.put ("Enable", "true"); 

Method needs to be invoked after the SHARESDK.INITSDK () method, and if SHARESDK.STOPSDK () is called, the Sharesdk.setplatformdevinfo () method needs to be called back after SHARESDK.INITSDK. For a more detailed explanation of the different fields of the application information, refer to the description of the Sharesdk.xml file header.

Fourth Step: Configure Androidmanifest.xml

Different integration needs to be added to the Androidmanifest.xml content. But first you need to add the following list of permissions:

<uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android: Name= "Android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name= " Android.permission.CHANGE_WIFI_STATE "/>
<uses-permission android:name=" android.permission.GET_ ACCOUNTS "/>
<uses-permission android:name= android.permission.MANAGE_ACCOUNTS"/>
< Uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
<uses-permission android:name= " Android.permission.WRITE_EXTERNAL_STORAGE "/>
<uses-permission android:name=" android.permission.GET_ TASKS "/>

These permissions will allow your project and SHARESDK to determine whether the current application is "forward", get permission to connect to the network, get permissions for the network status of your device, access the HTTPS secure connection, read the status of the handset device, and save the necessary configuration permissions. In general, most projects will register for these permissions even if the SHARESDK is not integrated.

Second, the following activity needs to be registered under application in order for the licensing operation to be completed successfully:

<activity
android:name= "Com.mob.tools.MobUIShell"
android:theme= "@android: style/ Theme.Translucent.NoTitleBar "
android:configchanges=" Keyboardhidden|orientation|screensize "
android: screenorientation= "Portrait"

If your project is a micro-trust or micro-trust circle, check the package path in the Androidmanifest.xml configuration file and create WXAPI directory under package directory to place wxentryactivity. Without this activity the callback will check for this activity after the micro-letter sharing and no error will be expected.

<activity 
android:name= ". Wxapi. Wxentryactivity "
android:theme=" @android: Style/theme.translucent.notitlebar " 
android:configchanges=" Keyboardhidden|orientation|screensize " 
android:exported=" true " 

And if your project set is easy to trust on two platforms, please check the package path in the Androidmanifest.xml configuration file to create YXAPI directory under package directory in place callback activity:

<activity 
android:name= ". Yxapi. Yxentryactivity " 
android:theme=" @android: Style/theme.translucent.notitlebar "
android:configchanges=" Keyboardhidden|orientation|screensize " 
android:exported=" true " 

The client's action callback, so SHARESDK cannot give you the action callback. To avoid errors, use a relative path to copy the above code directly into your androidmanifest.xml.

Step Fifth: Add code

Open the entry activity for your project and insert the following code in its oncreate: If you use the Sharesdk.xml method to configure the call

SHARESDK.INITSDK (this);

If you use a code configuration to apply registration information or apply a background configuration to apply registration information, call

SHARESDK.INITSDK (This, "Androidv1101″");

ANDROIDV1101: Is the Appkey that your application returns when SHARESDK registers the application information. The code initializes the SHARESDK, and thereafter the operations on SHARESDK are based on this. If this line of code is not invoked before all SHARESDK operations, a null pointer exception is thrown.

Effect Chart:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.