猿问

无法从Android中的Firebase Storge获取下载URL

无法从Android中的Firebase Storge获取下载URL。我得到:


com.google.android.gms.tasks.zzn@

而不是网址下载链接。我的代码:


storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {

@Override

            public void onSuccess(Uri uri) {

                uri1=uri;

                downloadURL =uri.toString();

                            // Got the download URL for 'users/me/profile.png'

            }

            }).addOnFailureListener(new OnFailureListener() {

                @Override

                             public void onFailure(@NonNull Exception exception) {

                                 // Handle any errors

                             }

             });


 if(uri1==null&&downloadURL==null){

                 Toast.makeText(MainActivity.this, "error", Toast.LENGTH_SHORT).show();

             }else if(uri1==null){

                Toast.makeText(MainActivity.this, ""+downloadURL, Toast.LENGTH_SHORT).show();

             }else if(downloadURL==null) {

                            Toast.makeText(MainActivity.this, "" + uri1, Toast.LENGTH_SHORT).show();

             }


饮歌长啸
浏览 404回答 1
1回答

森林海

为了获取URL,您需要附加一个侦听器。因此,为解决此问题,请使用以下代码:ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onSuccess(Uri uri) {&nbsp; &nbsp; &nbsp; &nbsp; String uri = uri.toString();&nbsp; &nbsp; &nbsp; &nbsp; Log.d("TAG", uri);}).addOnFailureListener(new OnFailureListener() {&nbsp; &nbsp; @Override&nbsp; &nbsp; public void onFailure(@NonNull Exception exception) {&nbsp; &nbsp; &nbsp; &nbsp; // Handle Errors&nbsp; &nbsp; }});
随时随地看视频慕课网APP

相关分类

Java
Android
我要回答