First step: Get SHARESDK
In order to integrate SHARESDK, you first need to register with the SHARESDK official website and create the application, get sharesdk appkey, then download the SDK's compression package on the download page of the SDK, extract the directory structure as follows:
Sharesdk in the "Sharesdk for Android" directory, the "Libs" in this directory contains "Mainlibs" and "Onekeyshare" are the core library of SHARESDK and "quick share" of the source library, the document is also in the " SHARESDK for Android "directory, be sure to read carefully before integrating SHARESDK. "sharesdk for Android apidoc" contains Javadoc for Mainlibs and Onekeyshare for developers to review. "sharesdk for Android sample" contains Sharesdk function demo code and APK file, sample source Javadoc in. "sharesdk for Androidservices" contains sharesdk already released "Plugin Services", for the time being we only provide "comments and likes" service, compressed package has provided this plug-in service's dependent library, sample code, Javadoc and apk files.
Step two: Import sharesdk
SHARESDK Integration Method:
1. Directly copy jar package to target Project Libs directory
You can refer to the sample project of SHARESDK for a direct copy of the jar and the resource. Using the Copy Jar method, you need to copy the pictures and strings in the mainlibs/res in addition to the jars in the mainlibs/libs, otherwise there will be an issue where resources are not found in authorization. And if your project is also integrated with the quick share, you also need to copy the source code in the 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. Quick Build Project
Since the integration of the direct copy jar package and the resource is cumbersome,SHARESDK provides a fast integrated program that can be executed directly under Windows, When you are finished, you can overwrite the files in the destination directory by copying them into your project. Greatly simplifies the process of integrating the "direct copy jar and resource" approach. for your project is just developed or want to write a Demo Test SHARESDK functionality that can be quickly integrated using this method
Step Three: Add app information
There are three different ways
first: configured in SHARESDK Application management background, Using this method requires calling SHARESDK.INITSDK (context, the Appkey) method that your app returns when SHARESDK registered, and if you later change the registration information can be changed directly from the web without having to republish the new version for the update. ( highest priority ) .
second: Configure by Code "Setplatformdevinfo ( String, hashmap<string, Object>) "method, use this method to initialize the method that calls Sharesdk.init (context, the Appkey that your app returns when SHARESDK registered). ( priority ) .
third: configured through the "Assets/sharesdk.xml" file, The secondary mode will exist in clear text, but this is the easiest way. ( lowest priority ) .
These three ways developers can choose their own, but these three kinds of settings are different: the first way to achieve the "dynamic configuration of Application Information" function, but once out of the network, SHARESDK may not work, the third way is the lowest priority, but it is the most convenient, centralized Finally, the way to use code is the most flexible way, the second way developers can write dead application information in the code, but also through the private protocol, from their own server to dynamically obtain application registration information, the priority of the first and second between. Use Sharesdk.xml Configure registration Information
<SHARESDKAppKey= "Fill in the Appkey you registered on SHARESDK" /><SinaweiboSortId= "The position of this platform in your share list, integer type, the larger the value, the more the back"AppKey= "Fill in the Appkey you registered on Sina Weibo"Appsecret= "Fill in the Appsecret you registered on Sina Weibo"Id= "custom field, Integer, identifier for this platform in your project"RedirectURL= "Fill in the RedirectURL you registered on Sina Weibo"sharebyappclient= "Whether to share with clients"Enable= "Boolean value that marks whether this platform is valid" />
Sharesdk.xml store data in XML format, each platform a block, in addition to social platforms, developers in SHARESDK registration application Appkey need to fill in the Block "SHARESDK", if this appkey is not the developer's own Appkey, The statistics will be incorrect in the future in the SHARESDK application background. Each SHARESDK platform has SortID, Id, enable four fields, in addition to the fields (such as Sina Weibo Appkey, Appsecret, RedirectURL, Sharebyappclient and other fields) need to be registered to the target platform after the application, please fill in the data of these fields correctly, otherwise SHARESDK cannot complete the authorization, then other operations will not be executed.
Example code configuration registration Information ( Demo Initialize Sina Weibo configuration information ) because the different sharing platform can set the configuration information, the specific sharing platform needs to set which configuration information, please refer to the Sharesdk.xml configuration file in the sample
sharesdk.initsdk (Context, "Your app returns at SHARESDK registration Appkey" <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"
The method needs to be called after the Sharesdk.initsdk () method, and if SHARESDK.STOPSDK () is called, the Sharesdk.setplatformdevinfo () method needs to be called again after SHARESDK.INITSDK. For a more detailed explanation of the different fields of application information, refer to the description of the Sharesdk.xml file header.
Fourth Step: Configure Androidmanifest.xml
Different integration needs to be added differently in Androidmanifest.xml. But first you need to add the following list of permissions:
<uses-permissionAndroid:name= "Android.permission.ACCESS_WIFI_STATE"/><uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE"/><uses-permissionAndroid:name= "Android.permission.CHANGE_WIFI_STATE"/><uses-permissionAndroid:name= "Android.permission.GET_ACCOUNTS"/><uses-permissionAndroid:name= "Android.permission.MANAGE_ACCOUNTS"/><uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE"/><uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permissionAndroid:name= "Android.permission.GET_TASKS"/><uses-permissionAndroid:name= "Android.permission.INTERNET"/>
These permissions will allow your project and SHARESDK to determine whether the current app is "pre-set", get permission to connect to the network, get permissions on the network status of your device, enable HTTPS secure connections, read the status of mobile devices, and save the necessary configuration permissions. In general, even if you do not integrate SHARESDK, most projects will register for these permissions.
Second, in order for the authorization operation to be completed successfully, the following activity needs to be registered under application:
< Activity Android:name = "Com.mob.tools.MobUIShell" android:theme= "@android: Style/theme.translucent.notitlebar" android: Configchanges= "Keyboardhidden|orientation|screensize" android:screenorientation = "Portrait" android:windowsoftinputmode= "Statehidden|adjustresize" />
If your project set or friends Circle, see Androidmanifest.xml Package path in the configuration file, need to create a wxapi directory in the package directory and then place wxentryactivity . Without this activity the callback will check for this activity after sharing and no error will be found.
< Activity Android:name = ". Wxapi. Wxentryactivity " android:theme=" @android: Style/theme.translucent.notitlebar " android:configchanges = "Keyboardhidden|orientation|screensize" android:exported= "true" android:screenorientation= "Portrait" />
And if your project set is easy to believe in two platforms, please check the package path in the Androidmanifest.xml configuration file to create the YXAPI directory in the catalog where the callback activity is placed:
< Activity Android:name = ". Yxapi. Yxentryactivity " android:theme=" @android: Style/theme.translucent.notitlebar " android:configchanges = "Keyboardhidden|orientation|screensize" android:exported= "true" android:screenorientation= "Portrait" />
The client's operation callback, so SHARESDK cannot give you an action callback. To avoid errors, use a relative path and copy the above code directly into your androidmanifest.xml .
Fifth Step: Add code
Open your project's entry activity and insert the following code in its oncreate: If the call is configured using Sharesdk.xml mode
SHARESDK.INITSDK (this);
If you use code to configure app registration information or apply background configuration app registration information, call
SHARESDK.INITSDK (This, "Androidv1101″");
ANDROIDV1101: Is the Appkey that your app returns when SHARESDK registers app information. The code initializes the SHARESDK, which is then based on the SHARESDK operation. If not all SHARESDK operation before calling this line of code, a null pointer exception is thrown .
:
Jerry Education
Source:http://www.cnblogs.com/jerehedu/
Copyright Notice: The copyright of this article belongs to cigarettes DeskJerry EducationSection Technology Co., Ltd. and blog Park are shared, welcome reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.
Technical Consultation:
Android Sharesdk for quick sharing