问题
the app force closes on calling GoogleApiClient.connect() method, atleast if it doesn't connect it should call onConnectionFailed, but dont know why my app is getting force closed. when i comment GoogleApiClient.connect() method it doesn't force close........ trying from hours together .
this is my code
package com.playservices.murali.playservices;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.plus.Plus;
public class MainActivity extends ActionBarActivity implements
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
@Override
protected void onStart()
{
super.onStart();
mGoogleApiClient.connect();
}
protected void onStop()
{
super.onStop();
//mGoogleApiClient.disconnect();
}
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
the error message log for the android is below image
回答1:
There are a few common sources of this error:
- Do you have your Play Games App ID properly defined in your
AndroidManifest.xml
? It should look like this:
In your application
tag:
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />
In the Google Play Developers console, have you added all of the correct accounts in the Testers tab? Any Google account that wants to use your application before it is published must be registered here.
Have you (properly) created a Client ID for your application? For Games make sure to do this in the Google Play Developer Console through the Linked Apps tab and not the Google Developer Console.
来源:https://stackoverflow.com/questions/28314978/clueless-why-app-is-get-force-closed-on-googleapiclient-connect