How to stop Google Play Games window from popping up if there is no INTERNET

336 views Asked by At

I use the Plus.API, Game.API, and Drive.API for IN-APP Purchases, LeaderBoards, and Saving game settings respectively.

Every time I enter the game the Google Play Games keeps popping up even though I refuse the login numerous times. How can I make the Games.API/Driver.API display the login only one time and if there is no INTERNET connection stop popping up until the next time the user starts the game?

This is my code:

//--------------------- Google API INIT
mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)   //used for Screenshot posting and Google Account for google api services
    .addApi(Games.API).addScope(Games.SCOPE_GAMES)      //user for Leaderboards
    .addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER)  //used for Game Saving
    .build();


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

@Override
protected void onStop() {
    if (mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
    super.onStop();
}
1

There are 1 answers

0
Rivero On BEST ANSWER

In your code, you are using the .connect() method of the API. This will try to connect to the service to authenticate with G+. If you wish to avoid this scenario in case the user closes the popup/button the first time, you'll have to store this as Preference Setting in your app and manage it from within your code.

As for checking the connection status, please check the implementation found here: How to check internet access on Android? InetAddress never times out