5

Getting FileNotFoundException on folders having space on Android 5.1. Otherwise its working fine. I tried replacing space with %20 but din't work. Also tried URLEncoder but it's failing.

I'm getting path of image using contentresolver:

absolutePathOfImage=cursor.getString(column_index_data);

which is (/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20181025-WA0001.jpg)

Uri:

file:///storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20181024-WA0022.jpg

I want to get bitmap of image but while getting bitmap from Uri, BitmapUtils throwing exception: (Note: even Glide,picasso is failing to create thumbnail of image)

        BitmapUtils.decodeSampledBitmap(mContext, mUri, mWidth, mHeight);

java.lang.RuntimeException: Failed to load sampled bitmap: file:///storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20181024-WA0022.jpg /storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20181024-WA0022.jpg: open failed: ENOENT (No such file or directory)

I'm getting exception on Android 5.1. Same code working on Android 8.0

Stuck with it since 2 days. Any workaround or solution?

AskQ
  • 4,215
  • 7
  • 34
  • 61

1 Answers1

2

the space should not be encoded, alike an URL:

file:///storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20181024-WA0022.jpg

but it should be escaped with \, alike a Linux path:

file:///storage/emulated/0/WhatsApp/Media/WhatsApp\ Images/IMG-20181024-WA0022.jpg

also make sure that the base-path file:///storage/emulated/0 is correct.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216