【问题标题】:getDownloadUrl is not working it says cannot find symbol method getDownloadUrl [duplicate]getDownloadUrl 不起作用,它说找不到符号方法 getDownloadUrl [重复]
【发布时间】:2021-05-04 15:59:29
【问题描述】:

我在我的更新按钮中设置了一个 onclicklistner,我想在 firebasestore(firestore 版本 22.1.2)中上传图像和用户名。我已经在 gradle 中添加了所有 firestore 依赖,getDownloadUrl 不起作用它说找不到符号方法 getDownloadUrl

String user_id = firebaseAuth.getCurrentUser().getUid();

StorageReference image_path = storageReference.child("profile_image").child(user_id+".jpg");

image_path.putFile(mainImageURI).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {

        if(task.isSuccessful()){
            Uri download_uri = task.getResult().getDownloadUrl(); //Have error in this getDownloadUrl().

            Map<String,String> userMap = new HashMap<>();
            userMap.put("name",user_name);
            userMap.put("image",download_uri);
            firebaseFirestore.collection("Users").document(user_id).set(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {

                    if(task.isSuccessful()){
                        finish();
                        Toast.makeText(SetupActivity.this,"The User Settings are updated ", Toast.LENGTH_LONG).show();
                        Intent mainIntent = new Intent(SetupActivity.this, MainActivity.class);
                        startActivity(mainIntent);


                    }else {
                        String error = task.getException().getMessage();
                        Toast.makeText(SetupActivity.this,"Firestore Error: "+error, Toast.LENGTH_LONG).show();

                    }
                    setupProgress.setVisibility(View.INVISIBLE);
                }
            });



        }else{
            String error = task.getException().getMessage();
            Toast.makeText(SetupActivity.this,"Image Error: "+error, Toast.LENGTH_LONG).show();

            setupProgress.setVisibility(View.INVISIBLE);
        }


    }
});

【问题讨论】:

    标签: android firebase firebase-storage


    【解决方案1】:
            public async Task getLinkAsync(string path)
            {
                FirebaseStorage storage = new FirebaseStorage("******-****.appspot.com");
                var starsRef = storage.Child(path);
                string link = await starsRef.GetDownloadUrlAsync();
            }
    

    【讨论】:

      猜你喜欢
      • 2020-11-13
      • 2018-11-08
      • 2020-02-08
      • 1970-01-01
      • 2018-11-06
      • 1970-01-01
      • 2019-06-26
      • 2019-11-18
      • 1970-01-01
      相关资源
      最近更新 更多