Android sharesdkqq third-party login so easy?

Source: Internet
Author: User
Tags openid

Yesterday, a group of friends saw me do before that QQ third-party login How to do, and then think about it, or decided to write a blog record. In fact it's not hard, in fact before I write to Facebook third party login don't know to look at this Android integrated Facebook login "-" Today just for example QQ login other like the need for tool signature and then md5+ package name.

I'm driving.

Preparations need to download SHARESDK here I don't repeat what I don't know about this article sharesdk social sharing of those years we stepped on the pits I don't repeat here because very many steps are repeated.

Then change your appkey by changing the Sharesdk.xml file under the assets file in Project projects

Then QQ third party login prepared jar click Direct Download OPENSDK
Then unzip the jar into the Libs in project, for example, as seen in the

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcxffmtu5ntazmju=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

1. Applications for AppID and Appkey

AppID: The unique identity of the app.

During the OAuth2.0 certification process. The value of AppID is the value of Oauth_consumer_key.

Appkey:appid the corresponding key, which is used to verify the legality of the application when visiting the user resource. During the OAuth2.0 certification process. The value of Appkey is the value of Oauth_consumer_secret.

2. Configuration manifest file Androidmainfest.xml
2.1 Join the relevant permissions

<!--Join Permissions -- <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" / > <uses-permission android:name="Android.permission.MANAGE_ACCOUNTS"/> <uses-permission android:name="Android.permission.GET_ACCOUNTS"/> <!--the required permissions for Bluetooth sharing--  <uses-permission android:name="Android.permission.BLUETOOTH" />  <uses-permission android:name="Android.permission.BLUETOOTH_ADMIN" / >
            <activity            android:name="com.mob.tools.MobUIShell"            android:configChanges="keyboardHidden|orientation|screenSize"            android:theme="@android:style/Theme.Translucent.NoTitleBar"            android:windowSoftInputMode="stateHidden|adjustResize">

2.2 Authorization Callbacks

<!--分享回调 -->           <activity            android:name=".wxapi.WXEntryActivity"            android:configChanges="keyboardHidden|orientation|screenSize"            android:exported="true"            android:screenOrientation="portrait"            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

2.3 Notes Activity

  <!--brochure Sdkactivity --           <activityandroid:name="com.tencent.tauth.AuthActivity"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="tencent1105658914" /> <!--open platform get appid--            </intent-filter>        </activity>         <activityandroid:name="com.tencent.connect.common.AssistActivity"Android : screenorientation="Portrait"android:theme="@android: style/ Theme.Translucent.NoTitleBar " />                                            <activity android:name=". Bdmap. Bmapactivity " />

3. Simple Code Implementation

declaring variables

    private Tencent mTencent;    private BaseUiListener mIUiListener;    private UserInfo mUserInfo;    private CallbackManager  mCallBackManager;

The majority of the SDK initialization will need to be noted here is the incoming Getapplicationcontext

  mTencent=Tencent.createInstance(AppConstant.APP_ID,LoginActivity.this.getApplicationContext());

3.1 QQ Login Authorization Interface Callback

    publicvoidQQLogin(View v) {        new BaseUiListener();        //all表示获取全部权限        mTencent.login(LoginActivity.this,"all", mIUiListener);        //授权成功后跳转到引导页面        startActivity(new Intent(LoginActivity.this,WelcomeGuideActivity.class));    }

3.2 After you define the listener to implement the Iuilistener interface, the 3 methods that need to be implemented OnComplete complete onerror error OnCancel Cancel

    /** * itself defines the listener after implementing the Iuilistener interface. 3 methods required to be implemented * OnComplete complete onerror error OnCancel cancel */    Private  class Baseuilistener implements Iuilistener{        @Override         Public void OnComplete(Object response) {Toast.maketext (loginactivity). This,"Authorized Success", Toast.length_short). Show (); LOG.E (TAG,"Response:"+ response); Jsonobject obj = (jsonobject) response;Try{String OpenID = obj.getstring ("OpenID"); String Accesstoken = obj.getstring ("Access_token"); String expires = obj.getstring ("Expires_in");                Mtencent.setopenid (OpenID);                Mtencent.setaccesstoken (Accesstoken,expires);                Qqtoken Qqtoken = Mtencent.getqqtoken (); Muserinfo =NewUserInfo (Getapplicationcontext (), Qqtoken); Muserinfo.getuserinfo (NewIuilistener () {@Override                     Public void OnComplete(Object response) {LOG.E (TAG,"Login Successful"+response.tostring ()); }@Override                     Public void OnError(Uierror uierror) {LOG.E (TAG,"Login Failed"+uierror.tostring ()); }@Override                     Public void OnCancel() {LOG.E (TAG,"Login Cancellation");            }                }); }Catch(Jsonexception e)            {E.printstacktrace (); }        }@Override         Public void OnError(Uierror uierror) {Toast.maketext (loginactivity). This,"Authorization Failed", Toast.length_short). Show (); }@Override         Public void OnCancel() {Toast.maketext (loginactivity. This,"Authorization Cancellation", Toast.length_short). Show (); }    }

3.3 Overriding the Onactivityresult method in the activity or fragment that invokes login

@Override    protectedvoidonActivityResult(intint resultCode, Intent data) {        if(requestCode == Constants.REQUEST_LOGIN){            Tencent.onActivityResultData(requestCode,resultCode,data,mIUiListener);        }               super.onActivityResult(requestCode, resultCode, data);    }

Summarize:

The entire process, as seen in the

Effects such as those seen in the 360 HD uncensored are loading in don't blink!

In order to make this thing to sell their own QQ is I easy? I can't do this, old driver!


Reprint please specify the source at the same time welcome everyone to add my group number. Welcome to drive, you can try to do it I may not be very complete here. It is best to suggest that you go to the network to see the document!

It should be no problem!

I'm a bit of a bad guy, and I don't like procrastination! Do what you like!

Because of the young!

Due to Caprice! Because the code is knocked out!

Remember that I have a group of friends code 9.99 ratings watercress Rod da!

Take a photo.

idkey=74044aec4b56f4a3528a19a40ffb830db1cbfbdb3831b1d0624416ac34175169 "target=" _blank ">

Android sharesdkqq third-party login so easy?

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.