How to make the error handling for Google Play Services outdated avoiding application crash in android?

0

I'm creating an application that uses Firebase , which in turn uses Google Play Services .

In my tests, when Google Play Services is outdated, it crashes the application and gives an error saying that the application has stopped.

Then a notification appears saying: Update Google Play Services - App only works with an updated version of Google Play Services.

Is it possible to make an error handling to warn the user that the Google Play Services update is required without crashing the application and closing it?

It's the error for me when I run this line:

 Button loginbtn = (Button) findViewById(R.id.loginbtn);
        loginbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               LoginProcess("[email protected] ", "senha123456");
            }
        });

...

public void LoginProcess(String email, String password){
    mAuth.signInWithEmailAndPassword(email, password)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        FirebaseUser user = mAuth.getCurrentUser();
                        Toast.makeText(getParent(), "Logado com sucesso.", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getParent(), "Falha de Login.", Toast.LENGTH_SHORT).show();
                    }
                }
            });
}
    
asked by anonymous 14.04.2018 / 07:04

1 answer

0

I was able to solve the problem as follows:

I found an outdated code on the net, after hours searching, and updating the new method was thus within a function that I created:

public Boolean GServicesCheck() {
    int result = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);

    switch(result) {
        case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
            Toast.makeText(this, "O Google Play Services precisa ser atualizado para acessar esta função.", Toast.LENGTH_SHORT).show();
            Log.d("FVRLOG","SERVICE_VERSION_UPDATE_REQUIRED");
            return false;
        case ConnectionResult.SUCCESS:
            Log.d("FVRLOG", "Play service available success");
            return true;
        default:
            Log.d("FVRLOG", "unknown services result: " + result);
            Toast.makeText(this, "Houve um erro com o Google Play Services, entre em contato com o administrador.", Toast.LENGTH_SHORT).show();
            return false;
    }
}

And now I check every time I'm going to run something that uses Google Play Services like this:

       @Override
        public void onClick(View view) {
         if(GServicesCheck()) {
           LoginProcess("[email protected] ", "senha123456");
         }
        }
    
14.04.2018 / 19:23