android share using third party (ShareSDK)

Without further ado, let's get straight to the point

1. Get Appkey

You need to enter the official website of shareSDK to get an appkey and App Secret

URL http://www.mob.com/

 

First you need to register a user and then log in. Then click to enter the background



 

 

Then add the application



 

After adding the application, the application will be generated



 

 

 

2. Download ShreSDK 

 

Download link: http://www.mob.com/downloads/

 

Then select the sdk you need, here we download android

 

 

 

After the download is complete and decompressed, this directory is



 3. Integrate shareSDK 

 

Here is the document address of the official integrated sdk: http://wiki.mob.com/



 

You can select the document you need and check it out.

 

 

At the same time, here is also an example of what I have done according to the official documentation

 

 

3.1 Import shareSDK into our project

 

We are using the citation method



 

 



 

 



 

If it prompts an error solution: Onekeyshare and Sharesdk set target=android-8 in the project.properties configuration file in the root directory of the project. If there is no Adnroid SDK of this version, please modify the version of the Android SDK you have and save it. Items are encoded in UTF-8.

 

3.2 Project references

Here Onekeyshare relies on Sharesdk

Select Onkeyshare right click -- "properties -- "android -- "add 

 

Then select the Sharesdk project right-click--"properties--"android--"is library



 

 

 

Then select our own app project right-click-"properties--"android--"add



 

 

Then select our own app project right click--"properties--"java build path--"Projects--"add

 



 

 

Then enter the shareSDK directory that was unzipped after downloading. Enter ShareSDK for Android\ Res

Copy the ShareSDK.xml file in the changed directory to your own project assert directory



 

Then open and add your own appkey



 
3.3 Modify manifest.xml

 

Then add the required permissions in the manifest.xml file

 

<!-- Add necessary permissions-->

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

<uses-permission android:name="android.permission.GET_TASKS" />

<uses-permission android:name="android.permission.INTERNET" />

<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.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

 

<!-- The SMS verification login function needs to add a secondary permission to automatically fill in the verification code, you can remove it if you don't use it -->

<uses-permission android:name="android.permission.RECEIVE_SMS" />

 

 

 

In order for the authorization operation to be completed successfully, the following Activity needs to be registered under the application:

 

<application

       android:name="com.mob.MobApplication">



       <!-- other activities -->



       <!-- ShareSDK的activity -->

<activity

     android:name="com.mob.tools.MobUIShell"

     android:theme="@android:style/Theme.Translucent.NoTitleBar"

     android:configChanges="keyboardHidden|orientation|screenSize"

     android:windowSoftInputMode="stateHidden|adjustResize" >

<!-- ShareSDK version 3.1.0 before this intent needs to be registered under MobUIShell, after version 3.1.0 (including 3.1.0) does not need to register this intent-->

     <intent-filter>

         <data android:scheme="tencent100371282" />

         <action android:name="android.intent.action.VIEW" />

         <category android:name="android.intent.category.BROWSABLE" />

         <category android:name="android.intent.category.DEFAULT" />

     </intent-filter>



    <!-- Call Sina native SDK, need to register callback activity -->

    <intent-filter>

        <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />

        <category android:name="android.intent.category.DEFAULT" />

    </intent-filter>



    <!--Integrated line client login authorization, you need to add a filter in the following format-->

    <intent-filter>

<data android:scheme="line.1477692153" />

<action android:name="android.intent.action.VIEW"/>

<category android:name="android.intent.category.BROWSABLE" />

<category android:name="android.intent.category.DEFAULT" />

    </intent-filter>



 </activity>

<!-- Fill in the Appkey and AppSecret you got from the Mob developer backend -->

<meta-data android:name="Mob-AppKey" android:value="您的AppKey"/>

<meta-data android:name="Mob-AppSecret" android:value="您的AppSecret"/>

</application>





If you integrate QQ sharing, or use QQ client to share QQ space, you need to add a callback activity here, a filter for the ACTION_VIEW event, where the scheme is the "tencent" prefix and the developer application plus appId. If this Activity and filter are not set, the correct callback cannot be obtained after the sharing ends.

<activity

     android:name="cn.sharesdk.tencent.qq.ReceiveActivity"

     android:launchMode="singleTask"

     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="tencent100371282" />

     </intent-filter>

</activity>

 

 

 

If your project set WeChat or WeChat Moments, please check the package path in the AndroidManifest.xml configuration file, you need to create a wxapi directory in the package directory and then place WXEntryActivity . If there is no such activity, the callback will check whether there is this activity after WeChat sharing, and if there is no such activity, an error will be reported.

 

 

For example, my project is configured with package in manifest.xml



 

Then the WXEntryActivity structure I added is  as follows



 

 

And if your project sets two platforms of Yixin, please check the package path in the AndroidManifest.xml configuration file. You need to create a yxapi directory in the package directory and place the callback Activity:

 

<activity     

    android:name=".yxapi.YXEntryActivity"     

    android:theme="@android:style/Theme.Translucent.NoTitleBar"

    android:configChanges="keyboardHidden|orientation|screenSize"

    android:exported="true"     

    android:screenOrientation="portrait" />

 

 

 

 

Add the following properties under the Application node:

 

android:name="com.mob.MobApplication"

My structure is as follows

 

 

 

 

Note: If you have your own Application class, you can also make your Application class inherit MobApplication.

 

 

4. Code and testing

First such a simple interface



 

Add event listener

public void shareTo(View v) {
		OnekeyShare oks = new OnekeyShare();
		// Turn off sso authorization
		oks.disableSSOWhenAuthorize();

		// This method is not called for the icon and text of Notification when sharing. Versions after 2.5.9
		// oks.setNotification(R.drawable.ic_launcher,
		// getString(R.string.app_name));
		// title title, used in Evernote, email, information, WeChat, Renren and QQ space
		oks.setTitle("Share");
		
		// titleUrl is the web link of the title, only used in Renren and Qzone
		oks.setTitleUrl("http://sharesdk.cn");
		
		
		// text is the share text, this field is required for all platforms
		oks.setText("I am sharing text");
		// imagePath is the local path of the image, all platforms other than LinkedIn support this parameter
		//oks.setImagePath("/sdcard/test.jpg");// Make sure this image exists under SDcard
		
		
		// comment is my comment on this share, only used on Renren and QQ space
		oks.setComment("I am the test comment text");
		
		// site is the name of the website that shares this content, and it is only used in QQ space (you may be prompted after the sharing is complete, whether to stay in QQ or return to the application This name is the application name)
		oks.setSite(getString(R.string.app_name));
		
		// siteUrl is the website address for sharing this content, only used in QQ space (click to change the address after sharing)
		oks.setSiteUrl("http://sharesdk.cn");
		// url is only used in WeChat (including friends and Moments)
		oks.setUrl("http://sharesdk.cn");
		// Start the sharing GUI
		oks.show(this);

	}

 

 

 

The operation effect is as follows



 


 





 

 

 



 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325339762&siteId=291194637