Pon*_*ing 7 android logout access-token
在Android应用程序中,
在一项活动中,我可以使用google plus登录,如下所述:https: //developers.google.com/+/mobile/android/sign-in
但我想从谷歌加上从不同的活动登出.所以,当我点击退出按钮然后我正在执行此代码...但是这里isConnected()方法总是返回false,因为用户不再连接..那么我如何使用AccessToken连接用户我从第一个活动存储?
if (mPlusClient.isConnected()) {
mPlusClient.clearDefaultAccount();
mPlusClient.disconnect();
Log.d(TAG, "User is disconnected.");
}
Run Code Online (Sandbox Code Playgroud)
那么我如何使用访问令牌从不同的活动中注销用户?
任何帮助将不胜感激.
登录适用于整个应用程序,因此您可以在应用程序中的任何位置注销。
注销活动。
在 Activity.onCreate 处理程序中初始化 GoogleApiClient 对象。
private GoogleApiClient mGoogleApiClient;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
Run Code Online (Sandbox Code Playgroud)
在 Activity.onStart 期间调用 GoogleApiClient.connect 。
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
//process sign out in click of button.
@Override
public void onClick(View view) {
if (view.getId() == R.id.sign_out_button) {
if (mGoogleApiClient.isConnected()) {
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
mGoogleApiClient.disconnect();
mGoogleApiClient.connect(); //may not be needed
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1628 次 |
| 最近记录: |