How To Logout From Google Using Google Account Credential Oauth2 (java)
I implement Google login using GoogleAccountCredential method. Init at onCreate method mCredential = GoogleAccountCredential.usingOAuth2( getApplicationContext(), Arra
Solution 1:
You have to call another thread like this :
publicclasssignoutextendsThread {
org.apache.http.HttpResponseresponse=null;
publicsignout(){
Log.i(TAG, "signout Session : Called");
}
@Overridepublicvoidrun() {
super.run();
response = response();
runOnUiThread(newRunnable() {
@Overridepublicvoidrun() {
if(response!=null){
Toast.makeText(mContext, "Sign Out Success", Toast.LENGTH_SHORT).show();
Log.i(TAG, "run: signOut: success "+response.toString() +" Response String : "+response.getStatusLine().toString());
// then remove Selected Account from preference : preferences particular Key is "PREF_ACCOUNT_NAME"
editor.putString(PREF_ACCOUNT_NAME, null);
editor.apply();
}else {
Log.i(TAG, "run: signOut: fail");
Toast.makeText(mContext, "Sign Out Fail", Toast.LENGTH_SHORT).show();
}
}
});
}
}
public org.apache.http.HttpResponse response()
{
org.apache.http.HttpResponseresponse=null;
try{
HttpClientclient=newDefaultHttpClient();
HttpPostpost=newHttpPost("https://accounts.google.com/o/oauth2/revoke?token="+mCredential.getToken());
response = client.execute(post);
}
catch(IOException | GoogleAuthException e)
{
Log.i(TAG, "run: RevokeAcess: Fail: "+e.getMessage());
}
CookieManager.getInstance().removeAllCookie();
return response;
}
Log Output On Success :
run: signOut: success org.apache.http.message.BasicHttpResponse@.... Response String : HTTP/1.1200 OK
So, for being more specific you can check for 200
Post a Comment for "How To Logout From Google Using Google Account Credential Oauth2 (java)"