无法从Android中的Firebase Storge获取下载网址。我明白了:
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();
}
谢谢你
答案 0 :(得分:1)
要获取网址,您需要附加一个监听器。因此,要解决此问题,请使用以下代码:
ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
String uri = uri.toString();
Log.d("TAG", uri);
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle Errors
}
});