【问题标题】:Not displaying the "User's Email address" and the data are not stored in the Firebase database不显示“用户的电子邮件地址”且数据未存储在 Firebase 数据库中
【发布时间】:2017-04-07 14:08:11
【问题描述】:

我已经完成了一个使用 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();
    }

}
}

这里出了什么问题?

为什么我无法保存数据?

请告诉我。

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

【问题讨论】:

  • 在Authentication部分注册用户,你仍然可以得到签名用户数据,例如姓名或照片url。
  • @AgiMaulana 我是 Firebase 和 Android Studio 的初学者,请详细说明

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


【解决方案1】:

您的 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();
            }

            // ...
        }
    });

【讨论】:

    猜你喜欢
    • 2016-12-09
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-29
    • 2015-10-06
    相关资源
    最近更新 更多