H
H
Hakito2016-01-14 01:22:22
Google
Hakito, 2016-01-14 01:22:22

What is the error when connecting to google API?

I am writing an android application using the google game services API.
An error occurs when trying to connect GoogleApiClient.
Here is what is written in the onConnectionFailed handler:
ConnectionResult{statusCode=RESOLUTION_REQUIRED, resolution=PendingIntent{413bd288: [email protected]}, message=null} I
wrote in the manifest:

<meta-data android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/google_app_id" />
        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

This is how I create the client:
client = new GoogleApiClient.Builder(this).addApi(Games.API).addScope(Games.SCOPE_GAMES).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();

Please tell me what is the problem? the second day I can not figure it out

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
glenean, 2016-01-14
@glenean

You are creating the client too early, this should be done in MainActivity in onCreate

H
Hakito, 2016-01-14
@Hakito

Here is my activation code. Now there is no error, but it just does not turn on. That is, OnConnected is not called

package hakito.pencilrunner.Activities;

import android.content.IntentSender;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.games.Games;

import hakito.pencilrunner.Game.Game;
import hakito.pencilrunner.R;

public class FinishActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    public static final String EXTRA_DISTANCE="distance";
    GoogleApiClient client;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_finish);


        findViewById(R.id.buttonRestart).setOnClickListener(this);

        client = new GoogleApiClient.Builder(this).addApi(Games.API).addScope(Games.SCOPE_GAMES).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();


    }

    @Override
    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.buttonRestart:
                Game.get().restart();
                finish();
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        client.connect();
    }

    @Override
    protected void onStop() {
        super.onStop();
        client.disconnect();
    }

    @Override
    public void onConnected(Bundle bundle) {
        int dist = getIntent().getIntExtra(EXTRA_DISTANCE, 0);

        Games.Leaderboards.submitScore(client, getString(R.string.leaderboard_best_score), dist);
        startActivity(Games.Leaderboards.getLeaderboardIntent(client, getString(R.string.leaderboard_best_score)));
    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        if(connectionResult.hasResolution())
        {
            try {
                connectionResult.startResolutionForResult(this, 0);
                client.connect();
            } catch (IntentSender.SendIntentException e) {
                e.printStackTrace();
            }
        }else {
            GooglePlayServicesUtil.showErrorDialogFragment(connectionResult.getErrorCode(), this, 0);
        }
    }
}

M
maaGames, 2016-01-14
@maaGames

Android Studio or Eclipse?
meta-data are written inside application?
What versions of the SDK were prescribed?
In the developer console, have these APIs been allowed for the application?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question