parsa
parsa

Reputation: 985

Firebase authentication asks for update for google play service

I want to create an EmailPassword authentication page as it can be inferred from the code below:

package parsa.lop.sibeh;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

public class MainActivity extends AppCompatActivity {
    private FirebaseAuth mAuth;
    private Button mLogin;
    private EditText mEmail;
    private EditText mPassword;
    private GoogleApiClient mGoogleApiClient;

    private FirebaseAuth.AuthStateListener mAuthListener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mAuth = FirebaseAuth.getInstance();
        mLogin = findViewById(R.id.login);
        mEmail = findViewById(R.id.email);
        mPassword = findViewById(R.id.password);
        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                if(firebaseAuth.getCurrentUser() != null){
                    startActivity(new Intent(MainActivity.this, StartActivity.class));
                }
            }
        };
    }

    @Override
    protected void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
    }

    public void loginButton(View view){

        String email = mEmail.getText().toString();
        String pass = mPassword.getText().toString();
        mAuth.signInWithEmailAndPassword(email, pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if(task.isSuccessful()){
                    Toast.makeText(MainActivity.this, "Signed In", Toast.LENGTH_LONG).show();
                }
            }
        });


    }
}

my app build.gradle contains

implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.1.0'

and my project build.gradle contains

classpath 'com.google.gms:google-services:4.2.0' 

i have created an account in firebase and i downloaded google-services.jsonin my app folder. so i don't get any errors except that when i click the button via loginButton() function i get a Notification from the emulator as to update the google play services

Upvotes: 0

Views: 79

Answers (1)

Gast&#243;n Saill&#233;n
Gast&#243;n Saill&#233;n

Reputation: 13129

All google services like Firebase , Google Maps and more works with google play services, if you dont have updated them , any of this services will run in your device, you will need to update them and make sure they are up to date.

To avoid users getting stuck at that window you can add a check to verify if the google play services version is up to date, if not you can redirect your users to update it

final String appPackageName = "con.google.android.gms"; // package name of the app

    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
    if(status == ConnectionResult.SUCCESS) {
        //alarm to go and install Google Play Services
    }else if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED){
       Toast.makeText(context,"please udpate your google play service",Toast.LENGTH_SHORT).show
   try {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
     } catch (android.content.ActivityNotFoundException anfe) {
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
    }

in your else statement we are redirecting the user to install it at this location

https://play.google.com/store/apps/details?id=com.google.android.gms

To update your Google Play Services from your emulator, refer to this answer updating Google play services in Emulator

Upvotes: 1

Related Questions