我实现了从图片库中提取图像的其余部分,并将其设置为图像视图!现在我想要的功能是上传用户个人资料图像和注册细节,也请注意,是否需要在用户模型类中增加一个变量?以及我必须在后面添加哪些参数、构造函数、getter或setter。下面也给出了用户模型类的代码,谢谢:)
//这是注册用户的函数:
private void register_doctor () {
String dname = et_name.getText().toString().trim();
String demail = et_email.getText().toString().trim();
String dpass = et_pass.getText().toString().trim();
String dcpass = et_cnf_pass.getText().toString().trim();
String dcontact = et_contact.getText().toString().trim();
String dcity = et_city.getText().toString().trim();
String dage = et_age.getText().toString().trim();
if (dname.isEmpty()) {
et_name.setError("Full Name is Required");
et_name.requestFocus();
return;
}
if (demail.isEmpty()) {
et_email.setError("Email is Required");
et_email.requestFocus();
return;
}
if (dpass.isEmpty()) {
et_pass.setError("Password is Required");
et_pass.requestFocus();
return;
}
if (dpass.length() < 6) {
et_pass.setError("Password Length Should be greater than 6 characters");
et_pass.requestFocus();
return;
}
if (dcpass.isEmpty()) {
et_cnf_pass.setError("Password is Required");
et_cnf_pass.requestFocus();
return;
}
if (!dcpass.equals(dpass)) {
et_cnf_pass.setError("Password Does not Matched!");
et_cnf_pass.requestFocus();
return;
}
if (dcontact.isEmpty()) {
et_contact.setError("Contact is Required");
et_contact.requestFocus();
return;
}
if (dcity.isEmpty()) {
et_city.setError("City is Required");
et_city.requestFocus();
return;
}
if (dage.isEmpty()) {
et_age.setError("Age is Required");
et_age.requestFocus();
return;
}
progressBar.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(demail, dpass)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
User user = new User(dname, demail, dcontact, dcity, dage);
FirebaseDatabase.getInstance().getReference("doctors")
.child("Doctors_Registration")
// .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.child(demail.replace(".", ","))
.setValue(user)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(signup.this, "Doctor Registered", Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
} else {
Toast.makeText(signup.this, "Failed to Registered, Try Again!" + task.getException(), Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
});
} else {
Toast.makeText(signup.this, "Failed to Registered, Try Again!", Toast.LENGTH_LONG).show();
progressBar.setVisibility(View.GONE);
}
}
});
}
// here is my user-model class code
package com.example.iotbaseddriverhealthmonitoring;
public class User {
public String name, email, password, contact, city, age;
public User(){
}
public User(String name, String email, String contact, String city, String age){
this.name = name;
this.email = email;
this.contact = contact;
this.city = city;
this.age = age;
}
}发布于 2022-02-26 19:13:59
我认为您的意思是setPhotoUri() (然后更新用户):
来自[消]火基文件
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName("Jane Q. User")
.setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
.build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated.");
}
}
});还可以将图像存储在Firebase存储中,然后将该下载链接保存在Firebase数据库中。
https://stackoverflow.com/questions/71279342
复制相似问题