I connect to my application via Google Sign-In.
Here is the code:
package com.tlalim.masa.parksclient.activities.user; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.app.ProgressDialog; import android.widget.Toast; 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.tlalim.masa.parksclient.R; import com.tlalim.masa.parksclient.activities.MainMenu; import com.google.android.gms.common.api.OptionalPendingResult; import com.google.android.gms.common.api.ResultCallback; public class CreateAccount extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener { private SignInButton signInButton; private GoogleApiClient googleApiClient; private int RC_SIGN_IN = 100; private static final String TAG = "SignInActivity"; private ProgressDialog mProgressDialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_account); GoogleSignInOptions gso = new GoogleSignInOptions.Builder( GoogleSignInOptions.DEFAULT_SIGN_IN) .requestEmail() .build(); googleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this, this) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); signInButton = (SignInButton) findViewById(R.id.sign_in_button); signInButton.setOnClickListener(this); signInButton.setSize(SignInButton.SIZE_WIDE); signInButton.setScopes(gso.getScopeArray()); } @Override public void onStart() { super.onStart(); OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn( googleApiClient); if (opr.isDone()) { // If the user's cached credentials are valid, the OptionalPendingResult will be "done" // and the GoogleSignInResult will be available instantly. Log.d(TAG, "Got cached sign-in"); GoogleSignInResult result = opr.get(); handleSignInResult(result); } else { // If the user has not previously signed in on this device or the sign-in has expired, // this asynchronous branch will attempt to sign in the user silently. Cross-device // single sign-on will occur in this branch. showProgressDialog(); opr.setResultCallback(new ResultCallback<GoogleSignInResult>() { @Override public void onResult(GoogleSignInResult googleSignInResult) { hideProgressDialog(); handleSignInResult(googleSignInResult); } }); } } @Override public void onClick(View v) { if (v.getId() == R.id.sign_in_button) { signIn(); } } private void signIn() { Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient); startActivityForResult(signInIntent, RC_SIGN_IN); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); //Calling a new function to handle signin handleSignInResult(result); } } private void handleSignInResult(GoogleSignInResult result) { //If the login succeed if (result.isSuccess()) { Intent intent1 = new Intent(getApplicationContext(), MainMenu.class); startActivity(intent1); } else { //If login fails Toast.makeText(this, "Login Failed", Toast.LENGTH_LONG).show(); } } private void showProgressDialog() { if (mProgressDialog == null) { mProgressDialog = new ProgressDialog(this); mProgressDialog.setMessage(getString(R.string.loading)); mProgressDialog.setIndeterminate(true); } mProgressDialog.show(); } private void hideProgressDialog() { if (mProgressDialog != null && mProgressDialog.isShowing()) { mProgressDialog.hide(); } } @Override public void onConnectionFailed(ConnectionResult connectionResult) { } }
Here are a few questions: I tried to find a solution, but the errors remain 1) The log shows such errors
I/GMPM: App measurement is starting up E/GMPM: getGoogleAppId failed with status: 10 E/GMPM: Uploading is not possible. App measurement disabled Can anyone explain what these statuses mean?
2) When I launch the application opens, and says that I need to get google play services, I press the get button and ProgressDialog () starts up, and after the answer returns, I understand it should turn off, but it does not turn off.
What am I doing wrong? How to solve at least some of the errors?