0

Images uploaded successfully on Firebase with imguri, however, when I want to load and display the image in the ListView, I got this error.

Some of my relevant code:

if (event.getImgUri() != null) {
            final String url = event.getImgUri();
            System.out.println(url);
            holder.imgview.setVisibility(View.VISIBLE);
            new AsyncTask<Void, Void, Bitmap>(){
                @Override
                protected Bitmap doInBackground(Void... params) {
                    return Utils.getBitmapFromURL(url);
                }
                @Override
                protected void onPostExecute(Bitmap bitmap) {
                    holder.imgview.setImageBitmap(bitmap);
                }
            }.execute();
        } else {
            holder.imgview.setVisibility(View.GONE);
        }

And

public static Bitmap getBitmapFromURL(String imageUrl) {
        Bitmap bitmap = null;
        if (bitmap == null) {
            try {
                URL url = new URL(imageUrl);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
               
                connection.setDoInput(true);
                connection.connect();
                InputStream input = connection.getInputStream(); 
                bitmap = BitmapFactory.decodeStream(input); 
            } catch (IOException e) {
                e.printStackTrace();
                Log.e("Error: ", e.getMessage().toString());
            }
        }

Any help will be appreciated.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Dark_Alex
  • 1
  • 1
  • What is the output of `System.out.println(url);`? – Frank van Puffelen Aug 16 '20 at 19:48
  • It's the firebase's uri, `I/System.out: com.google.android.gms.tasks.zzu@ef1a3e7`, not a downloadable url which I can use to get Bitmap from. – Dark_Alex Aug 16 '20 at 19:59
  • Maybe I am using a depreciated way to get the url, do you have any recommendations about how to implement this? thanks – Dark_Alex Aug 16 '20 at 20:03
  • That `com.google.android.gms.tasks.zzu@ef1a3e7` looks like your using `getDownloadUrl().toString()`, which is not the correct way to get a download URL anymore. Calling `getDownloadUrl()` returns a `Task` and you'll want to listen for that task to complete. See https://stackoverflow.com/questions/51056397/how-to-use-getdownloadurl-in-recent-versions and https://firebase.google.com/docs/storage/android/upload-files#get_a_download_url – Frank van Puffelen Aug 16 '20 at 20:03
  • Thanks for the clarification, this looks like the problem what I got from searching online, I will take an another look of my code and see if I can fix it. Appreciate your help. – Dark_Alex Aug 16 '20 at 20:08

0 Answers0