• Android第三方登录详解2


    接着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 public void onClick(View v) { // TODO Auto-generated method stub

    mController.doOauthVerify(mContext, SHARE_MEDIA.QQ, new UMAuthListener() { @Override public void onStart(SHARE_MEDIA platform) { Toast.makeText(mContext, "授权开始", Toast.LENGTH_SHORT).show(); } @Override public void onError(SocializeException e, SHARE_MEDIA platform) { Toast.makeText(mContext, "授权错误", Toast.LENGTH_SHORT).show(); } @Override public void onComplete(Bundle value, SHARE_MEDIA platform) { Toast.makeText(mContext, "授权完成", Toast.LENGTH_SHORT).show(); //获取相关授权信息 mController.getPlatformInfo(HomePage.this, SHARE_MEDIA.QQ, new UMDataListener() { @Override public void onStart() { Toast.makeText(HomePage.this, "获取平台数据开始...", 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()+" ");*/ // } //改成QQ头像 String u = (String) info.get("profile_image_url");
    //给imageview赋值 ImageLoader.getInstance().displayImage(u, tiouxiang); //qq用户名screen_name String name = (String) info.get("screen_name");
    //textview赋值 text_name.setText(" "+name); // Log.d("TestData",sb.toString()); }else{ Log.d("TestData","发生错误:"+status); } } }); } @Override public void onCancel(SHARE_MEDIA platform) { Toast.makeText(mContext, "授权取消"
    , Toast.LENGTH_SHORT).show(); } } ); } }); }

    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()+"
    ");
    //                                }
                                    //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) {}
    });
            
            
  • 相关阅读:
    java--对象引用与对象的区别
    小程序中js获取图片高度---多用于全屏广告图
    在WPF中显示GIF图片并实现循环播放
    在WPF中调用Winform控件
    开篇!WPF自定义控件(1)——转盘菜单
    【转】浅谈C#委托和事件
    给宝宝洗衣服,你应该按套路出牌
    代码复用,我应该知道的这些事
    Arrays.asList返回的List与new ArrayList的区别
    有关C++11标准的一些粗浅认识
  • 原文地址:https://www.cnblogs.com/1426837364qqcom/p/5286660.html
Copyright © 2020-2023  润新知