Uri downloaduri=taskSnapshot.getDownloadUrl();//here i cant use getdownloadurl() function
DatabaseReference new_prod=db.push();
new_prod.child("product name").setValue(prod_name);
new_prod.child("product price").setValue(prod_price);
new_prod.child("available stock").setValue(prod_quan);
new_prod.child("product image").setValue(downloaduri);
pd.dismiss();//fragments code
我无法使用 getdownloadurl 。我已经将图像存储在 firebase 存储中。是否是该 fragment 限制了 getdownloadurl 的使用?我的动机是进行查询以存储在 firebase 中。请帮助我。
最佳答案
最新版本的 Firebase Storage SDK 中删除了 taskSnapshot.getDownloadUrl()
方法。您现在需要从 StorageReference
获取下载 URL。
调用 StorageReference.getDownloadUrl()
会返回一个 Task
,因为它需要从服务器检索下载 URL。因此,您需要一个完成监听器来获取实际的 URL。
来自documentation on downloading a file :
storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() { @Override public void onSuccess(Uri uri) { // Got the download URL for 'users/me/profile.png' in uri System.out.println(uri.toString()); } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception exception) { // Handle any errors } });
或者,如果您在上传后立即获得下载 URL(如您的情况),则第一行可能是这样的:
taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
另请参阅:
关于android - 最新版本如何使用getdownloadurl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62089148/