第三方登陆--狸菇凉_

找着友盟的网页,自己注册一个号,在sdk文档中有步骤


1.导包:

2.权限

3.加入activity

4.添加友盟appkey

    

            android:name="UMENG_APPKEY"

            android:value="你的appkey" >

 

5建立一个application文件,随便起一个名字,比如叫App,别忘了在AndroidManifest文件中配置(如果本身已有,不需要重新建立):

6application文件中配置三方平台的appkey

 

PlatformConfig.setQQZone("你的qq appid", "key");

//初始化
UMShareAPI.get(this);
//设置qq平台的idkey
PlatformConfig.setQQZone("1106163122","aYFBhRfnHWXAkrPT");

 

  7.


/**
 * 姓名:孙盼盼
 * 时间:2017/5/12
 * 类用途:
 * 思路:
 */

public class LoginActivity extends AppCompatActivity{
    

    private UMAuthListener umAuthListener = new UMAuthListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
            //授权开始的回调
        }
        @Override
        public void onComplete(SHARE_MEDIA platform, int action, Map, String> data) {
            Toast.makeText(getApplicationContext(), "Authorize succeed", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onError(SHARE_MEDIA platform, int action, Throwable t) {
            Toast.makeText( getApplicationContext(), "Authorize fail", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA platform, int action) {
            Toast.makeText( getApplicationContext(), "Authorize cancel", Toast.LENGTH_SHORT).show();
        }
    };





    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        UMShareAPI umShareAPI = UMShareAPI.get(this);
        umShareAPI.getPlatformInfo(this,SHARE_MEDIA.QQ,umAuthListener);


    }


    @Override
回传值    

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

    }
}

 

  

 

////////////

授权失败解决方法:qq平台的idkey  换换,

//设置qq平台的idkey
PlatformConfig.setQQZone("1106086069","BbUDh6t7rYjJWowh");

 

你可能感兴趣的:(第三方登陆--狸菇凉_)