android - Google account choosing popup doesn't come after i had login once -


i facing issues google api. in pop of choosing account comes once. have activity , if logout, redirects me login page but, doesn't ask me choose accounts. want pop come everytime , while choosing account

here code :

import android.app.progressdialog; import android.content.intent; import android.content.sharedpreferences; import android.os.bundle; import android.support.annotation.nonnull; import android.support.v7.app.appcompatactivity; import android.view.view; import android.widget.edittext; import android.widget.toast;  import com.android.volley.authfailureerror; import com.android.volley.request; import com.android.volley.response; import com.android.volley.volleyerror; import com.android.volley.toolbox.stringrequest; import com.android.volley.toolbox.volley; import com.google.android.gms.auth.api.auth; import com.google.android.gms.auth.api.signin.googlesigninaccount; import com.google.android.gms.auth.api.signin.googlesigninoptions; import com.google.android.gms.auth.api.signin.googlesigninresult; import com.google.android.gms.common.connectionresult; import com.google.android.gms.common.signinbutton; import com.google.android.gms.common.api.googleapiclient; import com.google.android.gms.common.api.resultcallback; import com.google.android.gms.common.api.status;  import org.json.jsonexception; import org.json.jsonobject;  import java.util.hashmap; import java.util.map;   public class loginactivity extends appcompatactivity implements googleapiclient.onconnectionfailedlistener {       edittext edittextemail;     edittext edittextpass;     public static final int check=0;     private string name;     private string result;     private  string sem;     //signin button     private signinbutton signinbutton;      //signing options     private googlesigninoptions gso;      //google api client     private googleapiclient mgoogleapiclient;      //signin constant check activity result     private int rc_sign_in = 100;     string user_name,user_email;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_login);         sharedpreferences preferences = getsharedpreferences("myfile",mode_private);         boolean islogin = preferences.getboolean("islogin", false);          if (islogin)         {             startactivity(new intent(this, mainactivity.class));             finish();         }         gso = new googlesigninoptions.builder(googlesigninoptions.default_sign_in)                 .requestemail()                 .build();          intent intent = getintent();         string id = intent.getstringextra("keylog");           init();      }      private void init() {         signinbutton = (signinbutton) findviewbyid(r.id.sign_in_button);         signinbutton.setsize(signinbutton.size_wide);         signinbutton.setscopes(gso.getscopearray());         mgoogleapiclient = new googleapiclient.builder(this)                 .enableautomanage(this /* fragmentactivity */, /* onconnectionfailedlistener */)                 .addapi(auth.google_sign_in_api, gso)                 .build();         sharedpreferences preferencess = getsharedpreferences("chooseacc",mode_private);         string st= preferencess.getstring("rocks", "");         if(st=="rocks")         {             auth.googlesigninapi.signout(mgoogleapiclient).setresultcallback(                     new resultcallback<status>() {                         @override                         public void onresult(status status) {                             updateui(false);                         }                     });          }          //setting onclick listener signing button         signinbutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                 switch (view.getid()) {                     case r.id.sign_in_button:                         signin();                         break;                     // ...                 }             }         });      }      //this function option signing intent     private void signin() {         //creating intent         intent signinintent = auth.googlesigninapi.getsigninintent(mgoogleapiclient);          //starting intent result         startactivityforresult(signinintent, rc_sign_in);     }      /*public void login(view view) {          string email = edittextemail.gettext().tostring();         string pass = edittextpass.gettext().tostring();           hashmap<string, string> map = new hashmap<>();         map.put("id",email);         map.put("pass", pass);         map.put("key","appmakers");         callloginservice(map);     }*/     @override     public void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         //if signin         if (requestcode == rc_sign_in) {             googlesigninresult result = auth.googlesigninapi.getsigninresultfromintent(data);             //calling new function handle signin             handlesigninresult(result);         }     }       //after signing calling function     private void handlesigninresult(googlesigninresult result) {         //if login succeed         if (result.issuccess()) {             maintainsession();             //getting google account             googlesigninaccount acct = result.getsigninaccount();              //displaying name , email             user_name=acct.getdisplayname();             user_email=acct.getemail();             updateui(true);          } else {             //if login fails             toast.maketext(this, "login failed", toast.length_long).show();             updateui(false);         }     }      private void updateui(boolean b) {         if(b==true)         {             intent intent = new intent(this, mainactivity.class);             sharedpreferences preferences = getsharedpreferences("userinfo", mode_private);             sharedpreferences.editor editor = preferences.edit();             editor.putstring("name", ""+user_name);             editor.putstring("email", ""+user_email);             editor.commit();             startactivity(intent);             finish();         }         else             toast.maketext(this, "welcome login", toast.length_short).show();      }      private void callloginservice(final hashmap<string, string> map) {          final progressdialog dialog = new progressdialog(this);         dialog.setcancelable(false);         dialog.show();          stringrequest request = new stringrequest(request.method.post, urlhelper.login,                 new response.listener<string>() {                     @override                     public void onresponse(string response) {                         dialog.cancel();                         handlelogin(response);                      }                 }, new response.errorlistener() {             @override             public void onerrorresponse(volleyerror error) {                 dialog.cancel();                 toast.maketext(loginactivity.this, "error", toast.length_short).show();             }         }) {             @override   //use post data servers.             protected map<string, string> getparams() throws authfailureerror {                 return map;             }         };         volley.newrequestqueue(this).add(request);      }       private void handlelogin(string response) {         try {              toast.maketext(loginactivity.this, "hey", toast.length_short).show();             jsonobject object = new jsonobject(response);              if (object.getstring("result").equals("1")) {                  name=object.getstring("name");                 sem=object.getstring("sem");                 result=object.getstring("result");                 sharedpreferences preferences = getsharedpreferences("myresult", mode_private);                 sharedpreferences.editor editor = preferences.edit();                  editor.putstring("names",name);                 editor.putstring("sems",sem);                 editor.putstring("results",result);                 if(result.equals("1"))                 {                     editor.putboolean("islogin", true);                     maintainsession();                     startactivity(new intent(this,mainactivity.class));                     finish();                 }                 editor.commit();                 } else {                 toast.maketext(this, object.getstring("msg"), toast.length_short).show();             }         } catch (jsonexception e) {             e.printstacktrace();          }      }      private void maintainsession() {          sharedpreferences preferences = getsharedpreferences("myfile", mode_private);         sharedpreferences.editor editor = preferences.edit();         editor.putboolean("islogin", true);         editor.commit();     }       @override     public void onconnectionfailed(@nonnull connectionresult connectionresult) {         // unresolvable error has occurred , google apis (including sign-in) not         // available.         toast.maketext(this, "failed establish connection", toast.length_short).show();     }     @override     public void onbackpressed() {         finish();         super.onbackpressed();     }  } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -