java - Android Log In with Gmail not supported -
i 'm developing android application allows user login gmail . problem have integrating cycled clicking on log in button. here code use , idea why happens, or example can use?
public class androidgoogleplusexample extends activity implements onclicklistener, connectioncallbacks, onconnectionfailedlistener {
private static final int rc_sign_in = 0; // google client communicate google private googleapiclient mgoogleapiclient; private boolean mintentinprogress; private boolean signedinuser; private connectionresult mconnectionresult; private signinbutton signinbutton; private imageview image; private textview username, emaillabel; private linearlayout profileframe, signinframe; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); signinbutton = (signinbutton) findviewbyid(r.id.signin); signinbutton.setonclicklistener(this); image = (imageview) findviewbyid(r.id.image); username = (textview) findviewbyid(r.id.username); emaillabel = (textview) findviewbyid(r.id.email); profileframe = (linearlayout) findviewbyid(r.id.profileframe); signinframe = (linearlayout) findviewbyid(r.id.signinframe); mgoogleapiclient = new googleapiclient.builder(this).addconnectioncallbacks(this).addonconnectionfailedlistener(this).addapi(plus.api, plus.plusoptions.builder().build()).addscope(plus.scope_plus_login).build(); } protected void onstart() { super.onstart(); mgoogleapiclient.connect(); } protected void onstop() { super.onstop(); if (mgoogleapiclient.isconnected()) { mgoogleapiclient.disconnect(); } } private void resolvesigninerror() { if (mconnectionresult.hasresolution()) { try { mintentinprogress = true; mconnectionresult.startresolutionforresult(this, rc_sign_in); } catch (sendintentexception e) { mintentinprogress = false; mgoogleapiclient.connect(); } } } @override public void onconnectionfailed(connectionresult result) { if (!result.hasresolution()) { googleplayservicesutil.geterrordialog(result.geterrorcode(), this, 0).show(); return; } if (!mintentinprogress) { // store mconnectionresult mconnectionresult = result; if (signedinuser) { resolvesigninerror(); } } } @override protected void onactivityresult(int requestcode, int responsecode, intent intent) { switch (requestcode) { case rc_sign_in: if (responsecode == result_ok) { signedinuser = false; } mintentinprogress = false; if (!mgoogleapiclient.isconnecting()) { mgoogleapiclient.connect(); } break; } } @override public void onconnected(bundle arg0) { signedinuser = false; toast.maketext(this, "connected", toast.length_long).show(); getprofileinformation(); } private void updateprofile(boolean issignedin) { if (issignedin) { signinframe.setvisibility(view.gone); profileframe.setvisibility(view.visible); } else { signinframe.setvisibility(view.visible); profileframe.setvisibility(view.gone); } } private void getprofileinformation() { try { if (plus.peopleapi.getcurrentperson(mgoogleapiclient) != null) { person currentperson = plus.peopleapi.getcurrentperson(mgoogleapiclient); string personname = currentperson.getdisplayname(); string personphotourl = currentperson.getimage().geturl(); string email = plus.accountapi.getaccountname(mgoogleapiclient); username.settext(personname); emaillabel.settext(email); new loadprofileimage(image).execute(personphotourl); // update profile frame new info google account // profile updateprofile(true); } } catch (exception e) { e.printstacktrace(); } } @override public void onconnectionsuspended(int cause) { mgoogleapiclient.connect(); updateprofile(false); } @override public void onclick(view v) { switch (v.getid()) { case r.id.signin: googlepluslogin(); break; } } public void signin(view v) { googlepluslogin(); } public void logout(view v) { googlepluslogout(); } private void googlepluslogin() { if (!mgoogleapiclient.isconnecting()) { signedinuser = true; resolvesigninerror(); } } private void googlepluslogout() { if (mgoogleapiclient.isconnected()) { plus.accountapi.cleardefaultaccount(mgoogleapiclient); mgoogleapiclient.disconnect(); mgoogleapiclient.connect(); updateprofile(false); } } // download google account profile image, complete profile private class loadprofileimage extends asynctask<string, void, bitmap> { imageview downloadedimage; public loadprofileimage(imageview image) { this.downloadedimage = image; } protected bitmap doinbackground(string... urls) { string url = urls[0]; bitmap icon = null; try { inputstream in = new java.net.url(url).openstream(); icon = bitmapfactory.decodestream(in); } catch (exception e) { log.e("error", e.getmessage()); e.printstacktrace(); } return icon; } protected void onpostexecute(bitmap result) { downloadedimage.setimagebitmap(result); } }
manifest:
<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.get_accounts" /> <uses-permission android:name="android.permission.use_credentials" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Comments
Post a Comment