接着Android第三方登录详解1讲
1.找到友盟 文档中心
2.找到
3.将
UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.login"); |
|
这句话放到对应activity 弄成全局即可
4QQ 登录
//参数1为当前Activity, 参数2为开发者在QQ互联申请的APP ID,参数3为开发者在QQ互联申请的APP kEY. UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(this, "100424468", "c7394704798a158208a74ab60104f0ba"); qqSsoHandler.addToSocialSDK(); |
|
5将上述代码放到activity里 oncreate(Bundle savedInstanceState){}里 导包
6找到AndroidManifest.xml
7将下面代码沾到里面 添加 个权限 <uses-permission android:name="android.permission.GET_TASKS"/>
<!-- ############ QQ空间和QQ SSO授权的Activity注册 ############ --> <activity android: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="tencent你的QQ互联APPID" /> </intent-filter> </activity> <activity android:name="com.tencent.connect.common.AssistActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="portrait"> </activity> |
|
如图
8.在对应按钮监听里打
/** * QQ登录 * */ private void QQDengLu() { //监听 qq.setOnClickListener(new OnClickListener() { @Override mController.doOauthVerify(mContext, SHARE_MEDIA.QQ, new UMAuthListener() { /* for(String key : keys){ // } //改成QQ头像 // Log.d("TestData",sb.toString()); }else{ |
|
9.完成
10.微博登录接着上面打个微博监听里面打
mController.doOauthVerify(activity, SHARE_MEDIA.SINA,new UMAuthListener() { @Override public void onError(SocializeException e, SHARE_MEDIA platform) { } @Override public void onComplete(Bundle value, SHARE_MEDIA platform) { if (value != null && !TextUtils.isEmpty(value.getString("uid"))) { Toast.makeText(activity, "授权成功.",Toast.LENGTH_SHORT).show(); } else { Toast.makeText(activity, "授权失败",Toast.LENGTH_SHORT).show(); } mController.getPlatformInfo(activity, SHARE_MEDIA.SINA, new UMDataListener() { @Override public void onStart() { Toast.makeText(activity, "获取平台数据开始...", Toast.LENGTH_SHORT).show(); } @Override public void onComplete(int status, Map<String, Object> info) { if(status == 200 && info != null){ StringBuilder sb = new StringBuilder(); Set<String> keys = info.keySet(); // for(String key : keys){ // sb.append(key+"="+info.get(key).toString()+"\r\n"); // } //profile_image_url //改成微博头像 String u = (String) info.get("profile_image_url"); ImageLoader.getInstance().displayImage(u, tiouxiang); //微博用户名screen_name String name = (String) info.get("screen_name"); text_name.setText(" "+name); System.out.println(sb.toString()+"vvvvvvvvvvvvv"); Log.d("TestData",sb.toString()); }else{ Log.d("TestData","发生错误:"+status); } } }); } @Override public void onCancel(SHARE_MEDIA platform) {} @Override public void onStart(SHARE_MEDIA platform) {} }); |
|