简体   繁体   中英

Android Studio issue, having problem sigin up even when the password and email is correct. and am not gettin FCM token in my firebase account

I don't know if the problem is from the code. After signing up, when i try to log in, it shows "Wrong Credentials or Bad Connection, Try Again". which is the error to be called if the password is wrong or the email id is wrong.

firebaseAuth.signInWithEmailAndPassword(id,pass).addOnCompleteListener(SignInActivity.this, new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
        if(task.isSuccessful())
        {
            String id=editID.getEditText().getText().toString().trim()+"@gmail.com";
            db.collection("User").whereEqualTo("email",id).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    User obj=new User();
                    for(QueryDocumentSnapshot doc:queryDocumentSnapshots)
                        obj=doc.toObject(User.class);
                    FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {
                        @Override
                        public void onComplete(@NonNull com.google.android.gms.tasks.Task<String> task) {
                            try {
                                String token = task.getResult();
                                Log.e("DeviceToken = ",token);

                            }catch (Exception e){
                                e.printStackTrace();
                            }

                        }
                    });


                    db.document("User/"+firebaseAuth.getCurrentUser().getEmail()).update("fcmToken",SharedPref.getInstance(getApplicationContext()).getToken())
                            .addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {

                                    if(task.isSuccessful())
                                    {
                                        Toast.makeText(SignInActivity.this, "Registered for Notifications Successfully !", Toast.LENGTH_SHORT).show();
                                    }
                                    else
                                    {
                                        Toast.makeText(SignInActivity.this, "Registration for Notifications Failed !\nPlease Sign in Again to Retry", Toast.LENGTH_SHORT).show();
                                    }

                                }
                            });

If a Task fails, it contains an exception with additional information in why it failed. You should log that exception:

db.document("User/"+firebaseAuth.getCurrentUser().getEmail()).update("fcmToken",SharedPref.getInstance(getApplicationContext()).getToken())
  .addOnCompleteListener(new OnCompleteListener<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {

        if(task.isSuccessful())
        {
            Toast.makeText(SignInActivity.this, "Registered for Notifications Successfully !", Toast.LENGTH_SHORT).show();
        }
        else
        {
            // 👇
            Log.e("Auth", "Registration for Notifications Failed", task.getException());
            Toast.makeText(SignInActivity.this, "Registration for Notifications Failed !\nPlease Sign in Again to Retry", Toast.LENGTH_SHORT).show();
        }    
    }
});

Once you get the exception, search for the error message to see if others have dealt with the problem before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM