任何帮助将不胜感激! (与已贬值的DownloadURL()不同)
当我更新Android Studio并将所有代码移至AndroidX材质设计支持库时,问题就开始了。 (没想到会有那么多重建)
这是我当前的设置:
Log.d(TAG, "uploadNewPhoto: attempting to upload new photo");
FilePaths filePaths = new FilePaths();
//Case 1 new photo
if (photoType.equals(mContext.getString(R.string.profile_photo))){
String user_id = FirebaseAuth.getInstance().getCurrentUser().getUid();
StorageReference storageReference = mStorageReference
.child(filePaths.FIREBASE_IMAGE_STORAGE + "/" + user_id + "/photo" + (count + 1));
//Convert image url to bitmap
Bitmap bm = ImageManager.getBitmap(imgUrl);
byte[] bytes = ImageManager.getBytesFromBitmap(bm, 100);
UploadTask uploadTask = null;
uploadTask = storageReference.putBytes(bytes);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
****Uri filebaseUrl = taskSnapshot.getDownloadUrl();****
Toast.makeText(mContext, "Photo Upload Success!", Toast.LENGTH_SHORT).show();
//add new photo to photos node and user_photos node
//navigate to main feed so user can see photo
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "onFailure: Photo upload failed.");
Toast.makeText(mContext, "Photo upload failed. ", Toast.LENGTH_SHORT).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
if (progress - 15 > mPhotoUploadProgress){
Toast.makeText(mContext, "photo upload progress: " + String.format("%.0f", progress) + "%", Toast.LENGTH_SHORT).show();
mPhotoUploadProgress = progress;
}
}
});
}else if (photoType.equals(mContext.getString(R.string.profile_photo))){
}
//case 2 new profile photo
}
答案 0 :(得分:0)
找到相关问题的解决方案->
替换:
Uri filebaseUrl = taskSnapshot.getDownloadUrl();
使用
Task<Uri> firebaseUri = taskSnapshot.getStorage().getDownloadUrl();