Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Firebase Storage getDownloadUrl() method can't be resolved

General Tech Bugs & Fixes
Max. 2000 characters
Replies

usr_profile.png
Karlie Kloss

User

( 7 months ago )

 

To upload images to Firebase Storage I am attaching addOnSuccessListener on the instance of the StorageReference. While overriding onSuccess method I am calling getDownloadUrl() on the instance of taskSnapshot but it is giving me an error saying

Can't resolve method getDownloadUrl()

This app I had created 2 months ago, earlier this app was working fine and getDownloadUrl() was working fine as well. Also, in taskSnapshot instance when I press Ctrl+space, in the suggestions I don't find getDownloadUrl() method. Why is it happening?

Code to onActivityResult():

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            Toast.makeText(this, "Signed in!!!1", Toast.LENGTH_SHORT).show();
        } else if (resultCode == RESULT_CANCELED) {
            Toast.makeText(this, "Failed to sign in", Toast.LENGTH_SHORT).show();
            finish();
        }
    }
    else if(requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
        Uri selectedPhoto = data.getData();

        StorageReference localRefrence = storageReference.child(selectedPhoto.getLastPathSegment());

        //  Uploading the file on the storage
        localRefrence.putFile(selectedPhoto).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                 Uri downloadUrl = taskSnapshot.getDownloadUrl();

                FriendlyMessage message = new FriendlyMessage(mUsername, null, downloadUrl.toString());
                databaseReference.push().setValue(message);
            }
        });
    }
}

usr_profile.png
Deepak Parmar

User

( 7 months ago )

buttonSetup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String name = editText_name.getText().toString();
            if (!TextUtils.isEmpty(name) && mainImageURI != null) {
                final String user_id = firebaseAuth.getCurrentUser().getUid();
                progressBar_setup.setVisibility(View.VISIBLE);
                final StorageReference image_path = storageReference.child("profile_images").child(user_id + ".jpg");
                UploadTask uploadTask = image_path.putFile(mainImageURI);

                uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
                    @Override
                    public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
                        if(!task.isSuccessful()){
                            throw task.getException();
                        }
                        return image_path.getDownloadUrl();
                    }
                }).addOnCompleteListener(new OnCompleteListener<Uri>() {
                    @Override
                    public void onComplete(@NonNull Task<Uri> task) {
                        if (task.isSuccessful()){
                            Uri downloadUrl = task.getResult();
                            Log.i("The URL : ", downloadUrl.toString());
                        }
                    }
                });
            }
        }
    });

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif