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 存储中。是否是限制使用 getdownloadurl 的 fragment ?我的动机是查询存储在 firebase 中。请帮助我。
最佳答案
taskSnapshot.getDownloadUrl()
方法已在最新版本的 Firebase Storage SDK 中删除。您现在需要从 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/51056397/