我已经学会了如何从图库中选择图像,如何将其上传到firebase存储中,并将其显示在onActivityResult中,一切都很正常。我的问题是,当我重新启动活动时,映像就消失了。这是我的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_PHOTO && resultCode == RESULT_OK) {
Uri uri = data.getData();
StorageReference photoStorageReference = storageReference.child("Photos").child(uri.getLastPathSegment());
String path = storageReference.getPath(); //get the path of the last uploaded image
photoStorageReference.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUri = taskSnapshot.getDownloadUrl();
Picasso.with(StorageActivity.this).load(downloadUri).fit().centerCrop().into(imageView);
}
});
}
}我已经创建了一个名为displayLastImage()的方法。当我像这样从onCreate调用这个方法时:
private void displayLastImage() {
StorageReference newStorageReference = storageReference.child("Photos/car.jpg");
Glide.with(this).using(new FirebaseImageLoader()).load(newStorageReference).into(imageView);
}完美工作,但当我使用path而不是"Photos/46"从onCreate调用方法时,如下所示:
private void displayLastImage() {
StorageReference newStorageReference = storageReference.child(path);
Glide.with(this).using(new FirebaseImageLoader()).load(newStorageReference).into(imageView);
}我得到这个错误:java.lang.IllegalArgumentException: childName cannot be null or empty。如何获取上一张上传图片的path,以便正确显示?
提前感谢!
https://stackoverflow.com/questions/41521509
复制相似问题