I am following Google's documentation for Google Sign. Having a weird problem when I call
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent (mGoogleApiClient); startActivityForResult (signInIntent, RC_SIGN_IN);
Its seems Intent has been fired but I can't see account picker dialog. I am using
compile "com.google.android.gms:play-services-auth:9.6.1"
When I check does googleclient object is connected, it returns true.
Implementation
@OnClick (R.id.google_singin_button) void signInButtonClicked () { HashMap<String, Object> map = new HashMap<> (); map.put (AllAnalytics.LABEL, AllAnalytics.Label.SIGN_IN_GOOGLE); map.put (AllAnalytics.ACTION, AllAnalytics.Action.CLICK); map.put (AllAnalytics.CATEGORY, AllAnalytics.Category.REGISTRATION_SCREEN); aa.analyticsEventOccur (map); if (null != mGoogleApiClient) { // Log.e(TAG,mGoogleApiClient.isConnected()+""); Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent (mGoogleApiClient); startActivityForResult (signInIntent, RC_SIGN_IN); } } @Override public void onActivityResult (int requestCode, int resultCode, Intent data) { super.onActivityResult (requestCode, resultCode, data); // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); if(Activity.RESULT_CANCELED != resultCode) if (requestCode == RC_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent (data); handleSignInResult (result); } } @Override public void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); mActivity = (RegisterActivity) getActivity (); GoogleSignInOptions gso = new GoogleSignInOptions.Builder (GoogleSignInOptions.DEFAULT_SIGN_IN) .requestServerAuthCode (getString (R.string.google_client_auth), false) .requestEmail () .build (); mGoogleApiClient = new GoogleApiClient.Builder (getContext ()) .enableAutoManage (mActivity , this) .addApi (Auth.GOOGLE_SIGN_IN_API, gso) .build (); }
Log Cat
Class not found when unmarshalling: com.google.android.gms.auth.api.signin.internal.SignInConfiguration java.lang.ClassNotFoundException: com.google.android.gms.auth.api.signin.internal.SignInConfiguration at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:309) at java.lang.Class.forName(Class.java:273) at android.os.Parcel.readParcelableCreator(Parcel.java:2281) at android.os.Parcel.readParcelable(Parcel.java:2245) at android.os.Parcel.readValue(Parcel.java:2152) at android.os.Parcel.readArrayMapInternal(Parcel.java:2485) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.containsKey(BaseBundle.java:269) at android.content.Intent.hasExtra(Intent.java:4884) at com.miui.server.XSpaceManagerService.isPublicIntent(XSpaceManagerService.java:174) at com.android.server.am.ActivityStackSupervisorInjector.checkXSpaceControl(ActivityStackSupervisorInjector.java:56) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:897) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3478) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3465) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2245) at android.os.Binder.execTransact(Binder.java:446) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.auth.api.signin.internal.SignInConfiguration" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:309) at java.lang.Class.forName(Class.java:273) at android.os.Parcel.readParcelableCreator(Parcel.java:2281) at android.os.Parcel.readParcelable(Parcel.java:2245) at android.os.Parcel.readValue(Parcel.java:2152) at android.os.Parcel.readArrayMapInternal(Parcel.java:2485) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.containsKey(BaseBundle.java:269) at android.content.Intent.hasExtra(Intent.java:4884) at com.miui.server.XSpaceManagerService.isPublicIntent(XSpaceManagerService.java:174) at com.android.server.am.ActivityStackSupervisorInjector.checkXSpaceControl(ActivityStackSupervisorInjector.java:56) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:897) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3478) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3465) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2245) at android.os.Binder.execTransact(Binder.java:446) Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.auth.api.signin.internal.SignInConfiguration at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 19 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 10-11 23:46:17.873 1387-4537/? E/JavaBinder: *** Uncaught remote exception! (Exceptions are not yet supported across processes.) java.lang.RuntimeException: Parcel android.os.Parcel@33c1f490: Unmarshalling unknown type code 6684783 at offset 320 at android.os.Parcel.readValue(Parcel.java:2228) at android.os.Parcel.readArrayMapInternal(Parcel.java:2485) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.containsKey(BaseBundle.java:269) at android.content.Intent.hasExtra(Intent.java:4884) at com.miui.server.XSpaceManagerService.shouldResolveAgain(XSpaceManagerService.java:145) at com.android.server.am.ActivityStackSupervisorInjector.resolveXSpaceIntent(ActivityStackSupervisorInjector.java:68) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:898) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3478) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3465) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2245) at android.os.Binder.execTransact(Binder.java:446) 10-11 23:46:17.873 1387-4537/? A/ActivityManager: Activity Manager Crash java.lang.RuntimeException: Parcel android.os.Parcel@33c1f490: Unmarshalling unknown type code 6684783 at offset 320 at android.os.Parcel.readValue(Parcel.java:2228) at android.os.Parcel.readArrayMapInternal(Parcel.java:2485) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.containsKey(BaseBundle.java:269) at android.content.Intent.hasExtra(Intent.java:4884) at com.miui.server.XSpaceManagerService.shouldResolveAgain(XSpaceManagerService.java:145) at com.android.server.am.ActivityStackSupervisorInjector.resolveXSpaceIntent(ActivityStackSupervisorInjector.java:68) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:898) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:3478) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:3465) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2245) at android.os.Binder.execTransact(Binder.java:446)
3 Answers
Answers 1
Try to implement GoogleApiClient.ConnectionCallbacks
, GoogleApiClient.OnConnectionFailedListener
on your activity
and try code below
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); google_api_client = new GoogleApiClient.Builder(LoginActivity.this) .addConnectionCallbacks(LoginActivity.this) .addOnConnectionFailedListener(LoginActivity.this) .addApi(Plus.API) .addScope(Plus.SCOPE_PLUS_PROFILE) .addScope(Plus.SCOPE_PLUS_LOGIN) .build(); if (google_api_client.isConnected()) { google_api_client.connect(); } @Override protected void onStart() { super.onStart(); google_api_client.connect(); } @Override protected void onStop() { super.onStop(); if (google_api_client.isConnected()) { google_api_client.disconnect(); } } @Override public void onConnected(@Nullable Bundle bundle) { if (google_api_client.isConnected() && is_gglSignInBtn_clicked) { google_api_client.clearDefaultAccountAndReconnect(); } if (is_gglSignInBtn_clicked) { getProfileInfo(); is_gglSignInBtn_clicked = false; } } @Override public void onConnectionSuspended(int i) { google_api_client.connect(); } private void gPlusSignIn() { if (!google_api_client.isConnecting()) { if (is_gglSignInBtn_clicked && google_api_client.isConnected()) { google_api_client.clearDefaultAccountAndReconnect(); getProfileInfo(); } else { resolveSignInError(); } } } @Override public void onConnectionFailed(@NonNull ConnectionResult result) { if (!result.hasResolution()) { google_api_availability.getErrorDialog(this, result.getErrorCode(), request_code).show(); return; } if (!is_intent_inprogress) { connection_result = result; if (is_gglSignInBtn_clicked) { resolveSignInError(); } } } private void resolveSignInError() { if (connection_result != null) { if (connection_result.hasResolution()) { try { is_intent_inprogress = true; connection_result.startResolutionForResult(this, SIGN_IN_CODE); } catch (IntentSender.SendIntentException e) { is_intent_inprogress = false; google_api_client.connect(); } } } } private void getProfileInfo() { try { mProgressDialog.setMessage("Signing in...."); mProgressDialog.show(); if (Plus.PeopleApi.getCurrentPerson(google_api_client) != null) { Person currentPerson = Plus.PeopleApi.getCurrentPerson(google_api_client); Log.i("googleEmail", "" + (Plus.AccountApi.getAccountName(google_api_client))); email = "" + (Plus.AccountApi.getAccountName(google_api_client)); setPersonalInfo(currentPerson); } else { Toast.makeText(getApplicationContext(), "No Personal info mention", Toast.LENGTH_LONG).show(); finish(); } } catch (Exception e) { e.printStackTrace(); } } private void setPersonalInfo(Person currentPerson) { try { JSONObject googleJsonObject = new JSONObject(currentPerson + ""); familyName = googleJsonObject.getJSONObject("name").optString("familyName"); givenName = googleJsonObject.getJSONObject("name").optString("givenName"); gender = googleJsonObject.optString("gender"); displayName = googleJsonObject.optString("displayName"); googleId = googleJsonObject.optString("id"); imageUrl = "http://res.cloudinary.com/demo/image/gplus/" + googleId + ".jpg"; } catch (JSONException e) { e.printStackTrace(); }
Answers 2
Just check your onActivityResult()
is called or not because you have used Fragment
. So you have to pass the Activity
result from activity to fragment.
In your RegisterActivity
you have to write this
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_container); fragment.onActivityResult(requestCode, resultCode, data); }
and then you will receive result in your Fragment
.
Hope it helps you.
Answers 3
Have you tried disabling ProGuard? Set minifyEnabled to false in your build.gradle and see if it helps, your configuration may be out of date or incorrect.
Also you can check if your device is runing 9.6.1+ version of Google Play services.
0 comments:
Post a Comment