gpt4 book ai didi

java - 我如何在此 Activity 本身中获取 firebase 数据库

转载 作者:行者123 更新时间:2023-11-30 00:07:29 24 4
gpt4 key购买 nike

我的配置文件 Activity 代码如何在 EditText 和 ImageView 本身中设置此数据库

图片:

mSetupImageBtn = (CircleImageView) findViewById(R.id.setupImageBtn);

名字:

mNameField = (EditText)findViewById(R.id.setupNameField);





mStorageImage = FirebaseStorage.getInstance().getReference().child("Profile_Images");
mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("users");

mAuth = FirebaseAuth.getInstance();

mSetupImageBtn = (CircleImageView) findViewById(R.id.setupImageBtn);

mNameField = (EditText)findViewById(R.id.setupNameField);

mSubmitBtn = (Button)findViewById(R.id.setupSubmitBtn);


mSubmitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startSetupAccount();
}
});

mSetupImageBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent galleryIntent = new Intent();
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/e");
startActivityForResult(galleryIntent,GALLERY_REQUEST);
}
});

}

private void startSetupAccount() {

final String name = mNameField.getText().toString().trim();

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

if (!TextUtils.isEmpty(name) && mImageUri !=null){

mProgress.setMessage(getString(R.string.fin));

mProgress.show();

StorageReference filepath = mStorageImage.child(mImageUri.getLastPathSegment());

filepath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

@SuppressWarnings("VisibleForTests")

String downloadUri = taskSnapshot.getDownloadUrl().toString();



mDatabaseUsers.child(user_id).child("name").setValue(name);
mDatabaseUsers.child(user_id).child("image").setValue(downloadUri);

mProgress.dismiss();

Intent mainIntent = new Intent(SetupActivity.this,Main2Activity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(mainIntent);
finish();

}
});
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK){

mImageUri = data.getData();



CropImage.activity(mImageUri)
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1,1)
.start(this);

}

if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (resultCode == RESULT_OK){
Uri resultUri = result.getUri();

mSetupImageBtn.setImageURI(resultUri);

}else if (resultCode==CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE){
Exception error = result.getError();
}
}

最佳答案

检索数据:

 mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("users").child(user_id);
mDatabaseUsers.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String names=dataSnapshot.child("name").getValue().toString();
String images=dataSnapshot.child("image").getValue().toString();
Glide.with(ActivityNameHere.this).load(images).into(mSetupImageBtn);
mNameField.setText(names);
}

@Override
public void onCancelled(FirebaseError firebaseError) {


}
});

使用 Glide 库可以在 ImageView 中加载图像。

关于java - 我如何在此 Activity 本身中获取 firebase 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48732360/

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