@Override public void onComplete(Bundle values) { // 从 Bundle 中解析 Token mAccessToken = Oauth2AccessToken.parseAccessToken(values); // 从这里获取用户输入的 电话号码信息 String phoneNum = mAccessToken.getPhoneNum(); if (mAccessToken.isSessionValid()) { // 保存 Token 到 SharedPreferences AccessTokenKeeper.writeAccessToken(WelcomActivity.this, mAccessToken); Toast.makeText( WelcomActivity.this, R.string.weibosdk_demo_toast_auth_success, Toast.LENGTH_SHORT) .show(); startActivity(new Intent(WelcomActivity.this, MainActivity.class)); WelcomActivity.this.finish(); } else { // 以下几种情况,您会收到 Code: // 1. 当您未在平台上注册的应用程序的包名与签名时; // 2. 当您注册的应用程序包名与签名不正确时; // 3. 当您在平台上注册的包名和签名与您当前测试的应用的包名和签名不匹配时。 String code = values.getString("code"); String message = getString(R.string.weibosdk_demo_toast_auth_failed); if (!TextUtils.isEmpty(code)) { message = message + "\nObtained the code: " + code; } Toast.makeText(WelcomActivity.this, message, Toast.LENGTH_LONG).show(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcom); Oauth2AccessToken oauth2AccessToken = AccessTokenKeeper.readAccessToken(this); if (oauth2AccessToken != null && !TextUtils.isEmpty(oauth2AccessToken.getUid()) && !TextUtils.isEmpty(oauth2AccessToken.getToken()) && !TextUtils.isEmpty(oauth2AccessToken.getRefreshToken())) { startActivity(new Intent(this, MainActivity.class)); this.finish(); } else { mAuthInfo = new AuthInfo(this, Constants.APP_KEY, Constants.REDIRECT_URL, Constants.SCOPE); mSsoHandler = new SsoHandler(WelcomActivity.this, mAuthInfo); mSsoHandler.authorize(new AuthListener()); } }