Youmeng Third Party Login Blog

Third-party login is a very common login mode now, which is very popular among users. Let's do a third-party login of QQ.

1. Import the jar package and download it in Umeng in advance

2. Import the configuration file and have permission to set the activity

  1. <activity
  2. android:name="com.umeng.socialize.media.WBShareCallBackActivity"
  3. android:configChanges="keyboardHidden|orientation"
  4. android:theme="@android:style/Theme.Translucent.NoTitleBar"
  5. android:exported="false"
  6. android:screenOrientation="portrait" >
  7. </activity>
  8. <activity android:name="com.sina.weibo.sdk.web.WeiboSdkWebActivity"
  9. android:configChanges="keyboardHidden|orientation"
  10. android:exported="false"
  11. android:windowSoftInputMode="adjustResize"
  12. >
  13. </activity>
  14. <activity
  15. android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"
  16. android:launchMode="singleTask"
  17. android:name="com.sina.weibo.sdk.share.WbShareTransActivity">
  18. <intent-filter>
  19. <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
  20. <category android:name="android.intent.category.DEFAULT" />
  21. </intent-filter>
  22. </activity>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
3. Paste these codes into the activity you want to operate
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
}
4. You need to change the version number below 23 to 22. You need to write a page on the import dependency page.
MyApplication inherits Application and find it in the manifest file and write the following code

{

    PlatformConfig.setWeixin("wx967daebe835fbeac","5bb696d9ccd75a38c8a0bfe0675559b3");
    PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
    PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad","http://sns.whalecloud.com");
}
@Override
public void onCreate() {
    super.onCreate();
    // UMConfigure.init(this, UMConfigure.DEVICE_TYPE_PHONE, "1fe6a20054bcef865eeb0991ee84525b");
    UMConfigure.init(this,"5a12384aa40fa3551f0001d1"
            ,"umeng",UMConfigure.DEVICE_TYPE_PHONE,"");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0

    //UMShareAPI.get(this);


}

5.最后你要在想调用第三方点击事件里 写这些代码

UMAuthListener authListener = new UMAuthListener() {
    /**
     * @desc 授权开始的回调
     * @param platform 平台名称
     */
    @Override
    public void onStart(SHARE_MEDIA platform) {
    }
    /**
     * @desc 授权成功的回调
     * @param platform 平台名称
     * @param action 行为序号,开发者用不上
     * @param data 用户资料返回
     */
    @Override
    public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
        Toast.makeText(MainActivity.this, "成功了", Toast.LENGTH_LONG).show();
    }
    /**
     * @desc 授权失败的回调
     * @param platform 平台名称
     * @param action 行为序号,开发者用不上
     * @param t 错误原因
     */
    @Override
    public void onError(SHARE_MEDIA platform, int action, Throwable t) {
        Toast.makeText(MainActivity.this, "失败:" + t.getMessage(),                                     Toast.LENGTH_LONG).show();
    }
    /**
     * @desc 授权取消的回调
     * @param platform 平台名称
     * @param action 行为序号,开发者用不上
     */
    @Override
    public void onCancel(SHARE_MEDIA platform, int action) {
        Toast.makeText(MainActivity.this, "取消了", Toast.LENGTH_LONG).show();
    }
};
UMShareAPI umShareAPI = UMShareAPI.get(MainActivity.this);
umShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ,authListener);

Guess you like

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