I am creating a profile screen where it contains an image, which is not chosen in this registration screen. How can I load the default image for each new record. And the image is always the same (stored in Drawable), just changing the name to random.
This file will be stored in Firebase Storage and the path in Firebase Database.
I would like some ideas as best as possible to implement.
Note: I've seen some examples, but they all talk about capturing the gallery and then uploading it. In my case, the image is already in Drawable with the name of imagedefault.jpg
Code:
mAuth.createUserWithEmailAndPassword(email,senha).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if ( task.isSuccessful() ){
String user_id = mAuth.getCurrentUser().getUid();
/* Capture image in Drawable */
String imageUri = "drawable://" + R.drawable.imagedefault;
StorageReference storageRef = storage.getReference();
StorageReference mountainsRef = storageRef.child(imageUri);
/* Created node User */
DatabaseReference current_user_db = mDatabaseUsers.child(user_id);
current_user_db.child("name").setValue(edtName);
/* Created node Profile User */
DatabaseReference id_user = mDatabaseProfileUser.child(user_id);
id_user.child("user_name").setValue(edtUserName);
id_user.child("photo").setValue(??????);
mProgress.dismiss();
Toast.makeText(RegisterActivity.this, "Thanks register!!", Toast.LENGTH_SHORT).show();
Intent intentPos = new Intent(RegisterActivity.this, MainActivity.class);
intentPos.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentPos);
} else {
mProgress.dismiss();
Toast.makeText(RegisterActivity.this, "Error", Toast.LENGTH_LONG).show();
}
I TRIED TO CREATE AN EXAMPLE BUT IT IS NOT WORKING!!!
I got it to work, it was simply writing
imageRef = storageRef.child(RandomName() + "/pic");