不显示“用户的电子邮件地址”,并且数据未存储在Firebase数据库中

时间:2017-04-07 14:08:12

标签: java android firebase firebase-realtime-database firebase-authentication

我已经使用Firebase用户登录完成了一个项目。 当我点击注册按钮时,数据没有存储在firebase“Authetication-users”中。

  

ProfileActivity.java 代码

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class ProfileActivity1 extends AppCompatActivity implements View.OnClickListener {

private TextView textViewEmail;
private Button buttonLogout1;

private FirebaseAuth mAuth;

private FirebaseAuth.AuthStateListener mAuthListener;

private FirebaseUser user;

private static final String TAG ="FirebaseAuth";

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

    mAuth = FirebaseAuth.getInstance();

    mAuthListener = new FirebaseAuth.AuthStateListener() {


        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "Welcome Your:signed_in:" + user.getEmail());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");

                                }

        }


    };

}


@Override
public void onClick(View v) {

    if(v == buttonLogout1) {
        mAuth.signOut();
        Intent intent = new Intent(ProfileActivity1.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

}
}

这里出了什么问题?

为什么我无法保存数据?

请告诉我。

抱歉问题格式不正确。我还是个初学者。

1 个答案:

答案 0 :(得分:0)

您的createUserWithEmailAndPassword方法在哪里?它在你的代码中丢失了。您需要通过将新用户的电子邮件地址和密码传递给createUserWithEmailAndPassword来创建新帐户。

    mAuth.createUserWithEmailAndPassword(email,  password)
          .addOnCompleteListener(this, new      OnCompleteListener<AuthResult>() {
        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.
            if (!task.isSuccessful()) {
                Toast.makeText(EmailPasswordActivity.this, R.string.auth_failed,
                        Toast.LENGTH_SHORT).show();
            }

            // ...
        }
    });