我想使用uid从firebase中检索数据,这就是为什么我希望使用每个用户的个人资料数据like show in the image 从数据库中获取uid 我是Firebase的新手,所以有什么方法可以在用户注册时用用户的个人资料信息保存uid(我的意思是当他单击“创建帐户”按钮时)
我已附加了用于保存用户数据(带有图像)并保存用户身份验证数据(电子邮件和密码)的代码。 '''
cma.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressBar.setVisibility(View.VISIBLE);
//getting the data
final String username= un.getText().toString().trim();
String password= pw1.getText().toString().trim();
final String cpass= pw2.getText().toString().trim();
final String collegeid= cid.getText().toString().trim();
final String courses= cou.getText().toString().trim();
final String emailid= ei.getText().toString().trim();
final String status= sta.getText().toString().trim();
//for profile pic
String filePathAndName="ProfilePictures/"+"profile_"+ emailid;
if (circularImageView.getDrawable() != null) {
//get image from imageview
Bitmap bitmap = ((BitmapDrawable) circularImageView.getDrawable()).getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
//image compress
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
data = baos.toByteArray();
StorageReference ref = FirebaseStorage.getInstance().getReference().child(filePathAndName);
ref.putBytes(data)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//Success to firebase storage
Task<Uri> uriTask = taskSnapshot.getStorage().getDownloadUrl();
while (!uriTask.isSuccessful());
downloadUri = uriTask.getResult().toString();
if (uriTask.isSuccessful()) {
mauth.createUserWithEmailAndPassword(emailid,cpass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task){
if(task.isSuccessful()) {
//Custom Field save code
Student info = new Student(username,collegeid,courses,emailid,status,downloadUri);
reference.child(username).setValue(info).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task){
progressBar.setVisibility(View.GONE);
if(task.isSuccessful()) {
Toast.makeText(signup.this,"Successfully Completed !", Toast.LENGTH_SHORT).show();
Intent i = new Intent(signup.this, Welcome.class);
startActivity(i);
} else{
//Failure
}
}
});
//End custom field
} else{
Toast.makeText(signup.this, task.getException().getMessage(), Toast.LENGTH_SHORT).show();
}
//Authentication Stuff
}
});
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(signup.this, "Failed Uploading image", Toast.LENGTH_SHORT).show();
}
});
}
else { }
//Button Brackets
}
});
}'''