第三方登陆+获取头像

1.首先去官网下载SDK,并且创建新产品获取appkey,sdk粘贴到项目中
2.

implementation 'com.umeng.sdk:common:latest.integration'
    implementation 'com.umeng.sdk:analytics:latest.integration'

权限:


    
    
4.
        
            

            
            

            
        
    
    


    

5.创建app类,并且在清单文件里注册app的name
public class MyApplication_umeng extends Application {

@Override
public void onCreate() {
    super.onCreate();
   
    UMConfigure.init(this, "5a12384aa40fa3551f0001d1"
            , "umeng", UMConfigure.DEVICE_TYPE_PHONE, "");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0
    //开启log打印 报错会给你提示
    UMConfigure.setLogEnabled(true);
    PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0");
    //豆瓣RENREN平台目前只能在服务器端配置
    PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com");
    PlatformConfig.setYixin("yxc0614e80c9304c11b0391514d09f13bf");
    PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
    PlatformConfig.setTwitter("3aIN7fuF685MuZ7jtXkQxalyi", "MK6FEYG63eWcpDFgRYw4w9puJhzDl0tyuqWjZ3M7XJuuG7mMbO");
    PlatformConfig.setAlipay("2015111700822536");
    PlatformConfig.setLaiwang("laiwangd497e70d4", "d497e70d4c3e4efeab1381476bac4c5e");
    PlatformConfig.setPinterest("1439206");
    PlatformConfig.setKakao("e4f60e065048eb031e235c806b31c70f");
    PlatformConfig.setDing("dingoalmlnohc0wggfedpk");
    PlatformConfig.setVKontakte("5764965", "5My6SNliAaLxEm3Lyd9J");
    PlatformConfig.setDropbox("oz8v5apet3arcdy", "h7p2pjbzkkxt02a");

}

}
6.

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);

    }
7.点击拉取登陆窗口
 case R.id.btn:
          UMShareAPI umShareAPI =  UMShareAPI.get(MainActivity.this);
            UMShareConfig shareConfig = new UMShareConfig();
            shareConfig.isNeedAuthOnGetUserInfo(true);
                umShareAPI.setShareConfig(shareConfig);
            //开始登录
            //第一个参数:上下文
            //第二个参数,登录哪种平台
            //第三个参数,添加回调
            umShareAPI.getPlatformInfo(MainActivity.this, SHARE_MEDIA.QQ, new UMAuthListener() {
                /**
                 * 开始登录回调
                 * @param share_media
                 */
                @Override
                public void onStart(SHARE_MEDIA share_media) {
                    Log.i("dj", "UMAuthListener onStart");
                }

                /**
                 * 登录完成
                 * @param share_media
                 * @param i
                 * @param map
                 */
                @Override
                public void onComplete(SHARE_MEDIA share_media, int i, Map map) {
                    //头像,昵称,如果拿不到,自己debug看Key是啥,再问打死
                    Log.i("dj", "UMAuthListener onComplete");

                    //获取名字
                    String name  = map.get("screen_name");
                    //获取头像
                    String img  = map.get("profile_image_url");

                    Glide.with(MainActivity.this).load(img).into(imageview);
                    Log.i("dj", "name is "+ name);
                    Log.i("dj", "img is "+ img);
                }

                /**
                 * 登录失败
                 * @param share_media
                 * @param i
                 * @param throwable
                 */
                @Override
                public void onError(SHARE_MEDIA share_media, int i, Throwable throwable) {
                    Log.i("dj", "UMAuthListener onError" + throwable.getLocalizedMessage());
                }

                /**
                 * 登录取消
                 * @param share_media
                 * @param i
                 */
                @Override
                public void onCancel(SHARE_MEDIA share_media, int i) {
                    Log.i("dj", "UMAuthListener onCancel");
                }
            });


            break;

你可能感兴趣的:(第三方登陆+获取头像)