我正在使用此代码来检索存储在Firebase存储器中的图像的Uri,并将此图像检索到用户piture中,这是我的代码:
final StorageReference fileReference = storageReference.child(System.currentTimeMillis()
+ "." + getFileExtension(imgUri));
uploadTask = fileReference.putFile(imgUri);
uploadTask.continueWith(new Continuation<UploadTask.TaskSnapshot,Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if(!task.isSuccessful()){
throw task.getException();
}
return fileReference.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>(){
@Override
public void onComplete(@NonNull Task<Uri> task) {
if(task.isSuccessful()){
Uri downloadUri = task.getResult();
String mUri = downloadUri.toString();
reff = FirebaseDatabase.getInstance().getReference().child("Users")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
.child("Information");
HashMap<String,Object> map = new HashMap<>();
map.put("ImageURL",mUri);
reff.updateChildren(map);
它向我抛出此错误:java.lang.ClassCastException:com.google.android.gms.tasks.zzu无法转换为android.net.Uri
解决方案是什么?
更改
Uri downloadUri = task.getResult();
String mUri = downloadUri.toString();
至String mUri= task.getResult().getDownloadUrl().toString();