Google Play network connection doesnt work

50 views Asked by At

I am trying to connect my App to Google Play Services, for to add games achievements, but it doesn´t connect. It returns me this message:

Failed to sign in. Please check your network connection and try again.

I reinstalled Google Services, and it didn´t fix the problem. Here is my code.

public class MainActivity extends AppCompatActivity implements
        GoogleApiClient.ConnectionCallbacks,
        GoogleApiClient.OnConnectionFailedListener
{
    public static  GoogleApiClient googleApiClient;
    private static int RC_SIGN_IN = 9001;
    private boolean mResolvingConnectionFailure = false;
    private boolean mAutoStartSignInflow = true;
    private boolean mSignInClicked = false;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);

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

    @Override
    protected void onStart() {
        try
        {
            super.onStart();
            googleApiClient.connect();
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    @Override
    protected void onStop() {
        try
        {
            super.onStop();
            googleApiClient.disconnect();
        }catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    protected void onActivityResult(int requestCode, int resultCode,Intent intent)
    {
        if (requestCode == RC_SIGN_IN)
        {
            mSignInClicked = false;
            mResolvingConnectionFailure = false;
            if (resultCode == RESULT_OK)
            {
                googleApiClient.connect();
            }
            else
            {
                BaseGameUtils.showActivityResultError(this, requestCode, resultCode, R.string.error_conectar_google_juegos2);
            }
        }
    }


    @Override
    protected void onSaveInstanceState(Bundle outState)
    {
        super.onSaveInstanceState(outState);
        outState.putBoolean("STATE_RESOLVING_ERROR", false);
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) 
    {
        if (mResolvingConnectionFailure)
        {
            return;
        }

        if (mSignInClicked || mAutoStartSignInflow)
        {
            mAutoStartSignInflow = false;
            mSignInClicked = false;
            mResolvingConnectionFailure = true;
            if (!BaseGameUtils.resolveConnectionFailure(this,googleApiClient, connectionResult,RC_SIGN_IN, R.string.error_conectar_google_juegos1))
            {
                mResolvingConnectionFailure = false;
            }
        }
    }
}

The execution flow is the next:

  1. onCreate()
  2. onStart()
  3. onConnectionFailed()
  4. onSaveinstanceState()
  5. It asks for my Google Account
  6. onActivityResult()
  7. Here it goes to the "ELSE" of the onActivityResult().

When it fails, it shows the message I said before.

I have good internet connection on my device, and I use Android Games of Google Games with no problem. What can be happening?

Thank you so much.

0

There are 0 answers