Reputation: 845
I am trying to integrate a sign in feature for my app. But it crashes when the sign in button is pressed.
The log just shows that Signin button was clicked where mGoogleApiClient.connect(); is called and then it crashes. Also none of the Log in the Override methods are printed, so it doesn't go into any of the connection methods.So I am not able to figure out why the sign in is crashing.Is there any other @Override methods i need to implement?
06-09 16:44:05.820 13307-13307/com.appingapps.narayan.mancalapp D/Mancala﹕
Sign-in button clicked
W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception 06-09 16:44:05.895 13307-13307/com.appingapps.narayan.mancalapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: A fatal developer error has occurred.
My relevant code is as follows
public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { .....
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Create the Google Api Client with access to Plus and Games
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
...
}
protected void onStart() {
Log.d(TAG, "onStart()");
super.onStart();
// mGoogleApiClient.connect();
}
protected void onStop() {
Log.d(TAG, "onStop()");
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
private void showSignInBar() {
Log.d(TAG, "Showing sign in bar");
Button b = (Button)findViewById(R.id.signin);
b.setText("Sign In");
}
// Shows the "sign out" bar (explanation and button).
private void showSignOutBar() {
Log.d(TAG, "Showing sign out bar");
Button b = (Button)findViewById(R.id.signin);
b.setText("Sign Out");
}
Method that is called when signin button is clicked
public void signin(){
if(!mSignInClicked) {
mGoogleApiClient.connect();
Log.d(TAG, "Sign-in button clicked");
mSignInClicked = true;
}else{
mSignInClicked = false;
Games.signOut(mGoogleApiClient);
mGoogleApiClient.disconnect();
showSignInBar();
}
}
Override methods
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "onConnected() called. Sign in successful!");
showSignOutBar();
}
@Override
public void onConnectionSuspended(int i) {
Log.d(TAG, "onConnectionSuspended() called. Trying to reconnect.");
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed() called, result: " + connectionResult);
if (mResolvingConnectionFailure) {
Log.d(TAG, "onConnectionFailed() ignoring connection failure; already resolving.");
return;
}
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient,
connectionResult, RC_SIGN_IN, getString(R.string.signin_other_error));
}
showSignInBar();
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
Log.d(TAG, "in onActivityResult");
if (requestCode == RC_SIGN_IN) {
Log.d(TAG, "onActivityResult with requestCode == RC_SIGN_IN, responseCode="
+ responseCode + ", intent=" + intent);
mSignInClicked = false;
mResolvingConnectionFailure = false;
if (responseCode == RESULT_OK) {
mGoogleApiClient.connect();
} else {
BaseGameUtils.showActivityResultError(this,requestCode,responseCode, R.string.signin_other_error);
}
}
}
Upvotes: 2
Views: 2748
Reputation: 2023
add following with the app_id you registered from google in your Manifest file.
<meta-data android:name="com.google.android.gms.appstate.APP_ID"
android:value="@string/app_id" />
if you're using this games too you might need to add following as well
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
that could be the only reason. hope it helps
Upvotes: 6