Firebase存储“使用getDownloadUrl()检索长期下载URL”现已弃用

时间:2018-05-03 15:36:01

标签: java android firebase firebase-storage

getDownloadUrl()方法在更新为

后已弃用
  

'com.google.firebase:火力储存:15.0.2'

官方网站上没有任何其他方式可以实现网址,那么有什么办法以非弃用的方式实现网址?

/** @deprecated */
@Deprecated
@Nullable
public Uri getDownloadUrl() {
    StorageMetadata var1;
    return (var1 = this.getMetadata()) != null ? var1.getDownloadUrl() : null;
    }
}

3 个答案:

答案 0 :(得分:6)

在文档中它说:

  

getDownloadUrl()类的getDownloadUrls()StorageMetadata方法现已弃用。请改用getDownloadUrl()中的StorageReference

因此,您需要使用getDownloadUrl()

中的StorageReference
  

public Task<Uri> getDownloadUrl ()

     

使用可撤销令牌异步检索长期下载URL。这可用于与其他人共享文件,但如果需要,可由Firebase控制台中的开发人员撤消。

此处提供更多信息:

https://firebase.google.com/docs/reference/android/com/google/firebase/storage/StorageReference#getDownloadUrl()

答案 1 :(得分:4)

  final StorageReference filePath = mImageStore.child("profile_images").child("full_image").child(userId + ".jpg");
                filePath.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        //Bitmap hochladen
                        uploadBitMap(uri.toString());
                    }
                });strong text

final UploadTask uploadTask = thumb_file.putBytes(thumb_bite);
        uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {

                //Url laden
                taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        Map imageUrls = new HashMap();
                        imageUrls.put("image", fullImageUrl);
                        imageUrls.put("thumb_image", uri.toString());
                        //In database
                        mAlarmsDatabaseReference.updateChildren(imageUrls).addOnCompleteListener(new OnCompleteListener<Void>() {
                            @Override
                            public void onComplete(@NonNull Task<Void> task) {
                                //Progressbar beende + Bild wieder anzeigen
                                progressBar.setVisibility(View.GONE);
                                circleProfilePicture.setVisibility(View.VISIBLE);

                                if(task.isSuccessful()){
                                    Toast.makeText(SettingsActivity.this, getResources().getString(R.string.ProfilbildUpdate), Toast.LENGTH_SHORT).show();
                                }else{
                                    Toast.makeText(SettingsActivity.this, "FAILED", Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
                    }
                });
            }
        });

答案 2 :(得分:0)

最终UploadTask uploadTask = thumb_file.putBytes(thumb_bite);         uploadTask.addOnSuccessListener(new OnSuccessListener(){             @Override             公共无效onSuccess(UploadTask.TaskSnapshot taskSnapshot){

            //Url laden
            taskSnapshot.getStorage().getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                @Override
                public void onSuccess(Uri uri) {
                    Map imageUrls = new HashMap();
                    imageUrls.put("image", fullImageUrl);
                    imageUrls.put("thumb_image", uri.toString());
                    //In database
                    mAlarmsDatabaseReference.updateChildren(imageUrls).addOnCompleteListener(new OnCompleteListener<Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {
                            //Progressbar beende + Bild wieder anzeigen
                            progressBar.setVisibility(View.GONE);
                            circleProfilePicture.setVisibility(View.VISIBLE);

                            if(task.isSuccessful()){
                                Toast.makeText(SettingsActivity.this, getResources().getString(R.string.ProfilbildUpdate), Toast.LENGTH_SHORT).show();
                            }else{
                                Toast.makeText(SettingsActivity.this, "FAILED", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            });
        }
    });