I am trying to integrate google plus login with my application and I am partially succeded with it.I am able to login with google plus and I am able to fetch the email id of the logged in user.The only problem for me now is I need to implement logout from googleplus so that the app will redirect to the login page and it should show up the popup to select the id to login when user clicks on login button. I have gone through a lot of examples but in all they are implementing the login within the same activity.I am stuck up with this for almost an week with this issue. Kindly let me know how can I achieve the above. https://developers.google.com/+/mobile/android/sign-in this is the tutorial I followed for the login integration
This is my code in main activity
SharedPreferences shared = getSharedPreferences("MyPrefs", MODE_PRIVATE);
String channel = (shared.getString("logedin", ""));
Log.d("loggedin",channel);
if(channel.equals("false")){
revokeGplusAccess();
}
and this is my revokeGplusAccess function
private void revokeGplusAccess() {
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status arg0) {
Log.e(TAG, "User access revoked!");
mGoogleApiClient.connect();
updateUI(false);
}
});
}
And below is the code for my second activity where signout button is there
sharedpreferences = getSharedPreferences("MyPrefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("logedin", "false");
editor.commit();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
Below is the logcat error
java.lang.IllegalStateException: GoogleApiClient must be connected.
at com.google.android.gms.common.internal.zzu.zza(Unknown Source)
at com.google.android.gms.plus.Plus.zzf(Unknown Source)
at com.google.android.gms.internal.zzpa.clearDefaultAccount(Unknown Source)
at com.example.rating.Products.onSignedOut(Products.java:272)
at com.example.rating.Products.onClick(Products.java:139)
at android.view.View.performClick(View.java:4278)
at android.view.View$PerformClick.run(View.java:17429)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5099)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:803)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:570)
at dalvik.system.NativeStart.main(Native Method)