gpt4 book ai didi

java - 任务成功后附加参数未存储在 Firebase 数据库中?

转载 作者:行者123 更新时间:2023-12-02 11:33:00 25 4
gpt4 key购买 nike

这是我的 Register.java 页面。在这里,我无法在数据库中存储姓名和电话号码。当我尝试存储时没有响应。

public class Register extends AppCompatActivity {

private EditText mEmail;
private EditText mPassword;
private EditText mPhone;
private EditText mName;
private FirebaseAuth mAuth;
private ProgressBar progressBar;
DatabaseReference mData;


public void register(View v)
{
startRegister();
}

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

mAuth = FirebaseAuth.getInstance();
mEmail = (EditText)findViewById(R.id.email);
mPassword = (EditText) findViewById(R.id.password);
mPhone = (EditText) findViewById(R.id.phone);
mName = (EditText) findViewById(R.id.name);
mData=FirebaseDatabase.getInstance().getReference().child("Users");
progressBar = new ProgressBar(Register.this,null,android.R.attr.progressBarStyleLarge);



RelativeLayout layout = findViewById(R.id.layout);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(progressBar,params);
progressBar.setVisibility(View.INVISIBLE);


}

private void startRegister(){
String email = mEmail.getText().toString();
String password = mPassword.getText().toString();
final String phone = mPhone.getText().toString();
final String name = mName.getText().toString();

if(!TextUtils.isEmpty(password)&&!TextUtils.isEmpty(phone)&&!TextUtils.isEmpty(name)&&!TextUtils.isEmpty(email)){



mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(Register.this,new OnCompleteListener<AuthResult>() {



@Override
public void onComplete(@NonNull Task<AuthResult> task) {

if(task.isSuccessful()){

String user_id = mAuth.getCurrentUser().getUid();



DatabaseReference current_user_db = mData.child(user_id);

current_user_db.child("name").setValue(name);
current_user_db.child("phone").setValue(phone);
//mName.getText().toString() mPhone.getText().toString()

// getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
// progressBar.setVisibility(View.GONE);

// Intent main =new Intent(Register.this,MainActivity.class);
// startActivity(main);

}
}

});

}

}

}

我的gradle代码是 `应用插件:'com.android.application'

 android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.ashwanths.helpwithfood"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})

compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.google.firebase:firebase-database:11.8.0'
compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
testCompile 'junit:junit:4.12'
}




apply plugin: 'com.google.gms.google-services'`

或者您可以指定任何其他方式,让我可以同时添加所有数据数据的包括(姓名,电子邮件ID,密码,电话号码)

最佳答案

试试这个,因为这是注册而不是登录:

FirebaseUser users;
if(task.isSuccessful()){

users= task.getResult().getUser();
DatabaseReference ref = mData.child(users.getUid());
ref.child("name").setValue(name);
ref.child("phone").setValue(phone);

然后你将在数据库中拥有:

Users
useruid
name: name_here
phone: phone_here

关于java - 任务成功后附加参数未存储在 Firebase 数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49147698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com