W/System: Ignoring header X-Firebase-Locale because its value was null

六眼飞鱼酱① 提交于 2020-12-07 00:47:21

问题


Im very new to android studio. I'm trying to make a signup page with email and password authentication with Firebase. Howerver, whenever I try to click the sign up button it gives:

W/System: Ignoring header X-Firebase-Locale because its value was null

Can anyone tell me why?

Here is the SignupActivity.java file

package com.example.traintrack;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

import java.util.regex.Pattern;

public class SignupActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
    FirebaseAuth fAuth;
    Button signupBtn;       // Signup Button
    private String userType;
    private TextInputLayout textInputFullName;
    private TextInputLayout textInputEmail;
    private TextInputLayout textInputPassword;
    private boolean submitted = false, validUser = false;
    Spinner spinner;
    public static final Pattern VALID_EMAIL_ADDRESS_REGEX =
            Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);

    private String email;
    private String password;


    //Validating the signup page
    private boolean validateName(){
        String name = textInputFullName.getEditText().getText().toString().trim();

        if (name.isEmpty()){
            textInputFullName.setError("Field can't be empty");
        } else{
            textInputFullName.setError(null);
            return true;
        }

        return false;
    }
    private boolean validateEmail(){

        String email = textInputEmail.getEditText().getText().toString().trim();

        if (email.isEmpty()){
            textInputEmail.setError("Field can't be empty");
        } else if (!VALID_EMAIL_ADDRESS_REGEX.matcher(email).find()){
            textInputEmail.setError("Please enter a valid email");
        } else {
            textInputEmail.setError(null);
            return true;
        }
        return false;
    }

    private boolean validatePassword(){
        String password = textInputPassword.getEditText().getText().toString().trim();
        if (password.isEmpty()){
            textInputPassword.setError("Field can't be empty");
        } else if (password.length() < 8){
            textInputPassword.setError("Password must have at least 8 characters");
        } else {
            return true;
        }
        return false;
    }

    //public void confirm(View button){

    //}



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.signup);

        spinner = findViewById(R.id.signup_type);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.user_types, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);

        textInputFullName = findViewById(R.id.signup_fullname);
        textInputEmail =  findViewById(R.id.signup_email);
        textInputPassword =  findViewById(R.id.signup_password);
        signupBtn = findViewById(R.id.signup_confirm);


        //Firebase, Sign up by clicking the button
        fAuth = FirebaseAuth.getInstance();

        if (fAuth.getCurrentUser() != null)  // when the current user object is already present
          {
             startActivity(new Intent(getApplicationContext(), MainActivity.class));  //back to main page
             finish();
          }

        //register the user in firebase
        signupBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                password = textInputPassword.getEditText().getText().toString().trim();
                email = textInputEmail.getEditText().getText().toString().trim();

                // I have moved the validation here since this is the button for click
                submitted = true;
                if (!validateName() || !validateEmail() || !validatePassword() || !validUser){
                    Toast.makeText(SignupActivity.this, "Cannot create account", Toast.LENGTH_SHORT).show();
                    return;
                }


                fAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) //successfully created the user
                            {
                            Toast.makeText(SignupActivity.this, "Account created!", Toast.LENGTH_SHORT).show();
                            startActivity(new Intent (getApplicationContext(), MainActivity.class));
                            } else {

                            Toast.makeText(SignupActivity.this, "Error !", Toast.LENGTH_SHORT).show();
                        }
                    }
                });

            }
        });




    }//OnCreated Closing


    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        String type = parent.getItemAtPosition(position).toString();
        if (type.equals(getResources().getStringArray(R.array.user_types)[0]) && submitted){
            TextView errorText = (TextView)spinner.getSelectedView();
            errorText.setError("");
            errorText.setTextColor(Color.RED);
            errorText.setText("Please select a user type");
        } else {
            validUser = true;
            userType = type;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

}  //Ending
'''

回答1:


I have this issue only when I use the emulator on Android Studio. I searched and tested a bit and discovered that this problem doesn't appear when I use my own phone to launch my app. Like someone else stated before me it might be because of the wifi connection on the emulator.

(I'm quite new to Android Studio, I'm just sharing the way I solved it, hope it helps)

Use this to use your app on your own device: https://developer.android.com/studio/run/device




回答2:


Have you enabled the Email/Password Sign-in method on your Firebase console?

Firebase Console




回答3:


Make sure the emulator is connected to the internet. Sometimes the wifi is on but doesnt connect to the internet. This is how i fixed it anyway.




回答4:


Add this line to manifest.xml inside application tag:

android:usesCleartextTraffic="true"


来源:https://stackoverflow.com/questions/64727665/w-system-ignoring-header-x-firebase-locale-because-its-value-was-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!