我正在将图片上传到我的应用程序中的Firebase存储中。可以上传,并且可以在Firebase存储中在线查看。当我尝试获取它并在图像视图中显示它时,它没有出现在图像视图中,而是消失了。我已经尝试过Piccaso和滑行,但没有任何效果。代码附在下面
上传代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE && resultCode == RESULT_OK && data != null && data.getData() != null) {
uri = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
profile_image = findViewById(R.id.profileimage);
profile_image.setImageBitmap(bitmap);
imageRef=storageReference.child(userID);
imageRef.putFile(uri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//if the upload is successful
//hiding the progress dialog
//and displaying a success toast
//dismissDialog();
profilePicUrl = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
//if the upload is not successful
//hiding the progress dialog
// dismissDialog();
//and displaying error message
Toast.makeText(profile.this, exception.getCause().getLocalizedMessage(), Toast.LENGTH_LONG).show();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
下载并加载到图像视图代码中:
fbstorage=FirebaseStorage.getInstance();
storageReference=fbstorage.getReference();
imageRef=storageReference.child(userID);
final String h=imageRef.getDownloadUrl().toString();
storageReference.child(userID).getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
Toast.makeText(profile.this, "hello", Toast.LENGTH_SHORT).show();
Picasso.with(profile.this).load(h).into(profile_image);
}
});
答案 0 :(得分:0)
尝试滑行..此代码对我来说很好用
AssignmentPeriod