Google Sign IN in android application -
how can google sign in android application without using google plus . need sign in of google in app sign in facebook screen appeared ask fill username , password , click on sign in button.
i had sign directly using google play library , want prompt comes , ask username , password .
i got problem using google plus if body had google account not activated google plus account can in case?
i want google sign in way there way please give me solutions possible .
hi can use following approach: first of all, ask user enter email id in edittext , value on click of button, , proceed below:
//check whether account configured or not if(isaccountalreadyconfigured(emailid)){ //if email id entered user configured in device getgoogleapiclientinstance(emailid); connecttogoogleapiclient(); }else{ //if email id account not configured in device bundle accountoptions = new bundle(); accountoptions.putstring(accountmanager.key_account_name, emailid); accountoptions.putstring(accountmanager.key_account_type,constants.account_type); accountmanager.addaccount(constants.account_type, null, null, accountoptions, this, accountmanagercallback, null); } /* @method isaccountalreadyconfigured used check whether email address entered user * configured in device or not * @param string: takes email address parameter * @return boolean*/ private boolean isaccountalreadyconfigured(string accountname){ account[] accounts = accountmanager.getaccountsbytype(constants.account_type); for(account account: accounts ){ if(account.name.equals(accountname)){ //account alreadyconfiguredaccount = account; //use confirmcredentialsmethod return true; } log.i(log_tag, "account info: "+account.name + "\n" + "account type: "+account.type); } return false; } /* @method getgoogleapiclientinstance used googleapiclientinstance particular google account * @param string : gmail account id * @return googleapiclient instance * */ private googleapiclient getgoogleapiclientinstance(string accountname){ mgoogleapiclient = new googleapiclient.builder(this) .addapi(plus.api) .addscope(plus.scope_plus_login) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .setaccountname(accountname) .build(); return mgoogleapiclient; } /* @method connecttogoogleapiclient used connect googleapiclient instance google api servers */ private void connecttogoogleapiclient(){ if(mgoogleapiclient != null){ mgoogleapiclient.connect(); }else{ log.e(log_tag, "error connecting google api client"); } } /* accountmanagercallback used pass 1 of params accountmanager.addaccount method*/ private accountmanagercallback<bundle> accountmanagercallback = new accountmanagercallback<bundle>() { @override public void run(accountmanagerfuture<bundle> future) { futurebundle = future; log.i(log_tag, "done: " +future.isdone() + "\n" + "iscancelled: "+future.iscancelled()); handler.post(runnable); } }; private runnable runnable = new runnable() { @override public void run() { try { // futurebundle.getresult() call block until result available call on thread bundle bundle = futurebundle.getresult(); if(bundle != null){ log.i(log_tag, "result: "+bundle); string authaccount = bundle.getstring(accountmanager.key_account_name); string accounttype = bundle.getstring(accountmanager.key_account_type); /*result bundle should have authaccount , accounttype extras, acts confirmation account configured in device or can cross verify calling @method isaccountalreadyconfigured*/ if((authaccount.equals(emailid) && accounttype.equals(constants.account_type)) || isaccountalreadyconfigured(emailid)){ getgoogleapiclientinstance(emailid); connecttogoogleapiclient(); }else{ log.e(log_tag, "an error occured while configuring new account"); } } } catch (operationcanceledexception e) { e.printstacktrace(); } catch (authenticatorexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } } };
or can use below code if don't want use googleapiclient instance configured account ie. above if
if(isaccountalreadyconfigured(emailid)){ bundle accountoptions = new bundle(); accountoptions.putstring(accountmanager.key_account_name, emailid); accountoptions.putstring(accountmanager.key_account_type,"com.google"); accountmanager.confirmcredentials(account, accountoptions, this, accountmanagercallback, null); }
first parameter account of type account class can retrieve isaccountalreadyconfiguredmethod.
Comments
Post a Comment