Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用google plus的accessToken从不同活动注销android用户_Android_Logout_Access Token - Fatal编程技术网

如何使用google plus的accessToken从不同活动注销android用户

如何使用google plus的accessToken从不同活动注销android用户,android,logout,access-token,Android,Logout,Access Token,在Android应用程序中 在一个活动中,我可以使用google plus登录,如下所述: 但我想从不同的活动中从google plus注销。 所以,当我单击“注销”按钮时,我正在执行这段代码…但是这里的isConnected()方法总是返回false,因为用户不再连接..那么我如何使用从第一个活动存储的AccessToken连接用户呢 if (mPlusClient.isConnected()) { mPlusClient.clearDefaultAccount();

在Android应用程序中

在一个活动中,我可以使用google plus登录,如下所述:

但我想从不同的活动中从google plus注销。 所以,当我单击“注销”按钮时,我正在执行这段代码…但是这里的isConnected()方法总是返回false,因为用户不再连接..那么我如何使用从第一个活动存储的AccessToken连接用户呢

 if (mPlusClient.isConnected()) {
        mPlusClient.clearDefaultAccount();
        mPlusClient.disconnect();
        Log.d(TAG, "User is disconnected.");
    }  
那个么,我如何使用访问令牌从不同的活动中注销用户呢


任何帮助都将不胜感激。

登录适用于整个应用程序,因此您可以在应用程序的任何位置注销

签出活动

在Activity.onCreate处理程序中初始化GoogleAppClient对象

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();
}
在Activity.onStart期间调用GoogleAppClient.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
    }
  }
}

如果你找到了解决方案,请分享。