android - 如何在最新版本中使用 getdownloadurl?

标签 android firebase firebase-storage

                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/

相关文章:

android - 如何检查edittext是否为空?

android - PhoneGap Geolocation 在特殊设备上总是超时

c# - 无法通过 Unity 将数据写入 Firebase 数据库

java - 如何从 Firebase 存储获取 URL getDownloadURL

firebase - 如何从异步函数中正确获取字符串?

android - 无法发布应用程序,因为它被 Alpha 测试阻止

android - 如何在 KITKAT(4.4) 中使 Android Webview 背景透明

ios - Firebase Swift 3.0 语法更新?

firebase - 如何使用管理员权限模拟 Firebase Cloud Function 的数据库身份验证?

android - Firebase Storage getDownloadUrl() 方法无法解析