本文介绍了在Android应用程序中注销GoogleApiClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用此类代码可以链接我的应用程序并使用帐户。
if(mGoogleApiClient == null){
mGoogleApiClient =新的GoogleApiClient.Builder(this)
.addApi(Plus.API)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
。 addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
但是,在激活或切换到新帐户后,有什么方法可以从此帐户注销?
解决方案
我发现这个最新的解决方案:
<$ p $(){code> if(mGoogleApiClient!= null&& mGoogleApiClient.isConnected()){
mGoogleApiClient.clearDefaultAccountAndReconnect()。setResultCallback(new ResultCallback< Status>(){
@Override
public void onResult(状态状态){
mGoogleApiClient.disconnect();
}
});
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
不推荐使用
Using such code it is possible to link my app and use account.
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Plus.API)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
But is where any way to 'logout' from this account once activated or switch to a new one?
解决方案
I found this up-to-date solution:
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
mGoogleApiClient.clearDefaultAccountAndReconnect().setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
mGoogleApiClient.disconnect();
}
});
}
The usage of
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
is deprecated
https://developers.google.com/android/reference/com/google/android/gms/plus/Account
这篇关于在Android应用程序中注销GoogleApiClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!