AtanuCSE AtanuCSE - 1 year ago 113
Android Question

MediaStore returned thumbnail path but File object giving file not exist - Android

I got the thumbnail path of videos using

. MediaStore is giving me the thumbnail path. Now When I check for if the thumbnail path exists or not, it's giving me that
file not exists

I've found thumbnail path using

Cursor c = new CursorLoader(getApplicationContext(), MediaStore.Video.Thumbnails.getContentUri("external"), project, selection, selectionArgs, null).loadInBackground();
while(c.moveToNext()) {

//Toast.makeText(getApplicationContext(), c.getString(1),Toast.LENGTH_LONG).show();

Toasts showing a path like


So I decided to check if file exists before doing something with it.

File file = new File(paths);
if (file.exists())
Toast.makeText(getApplicationContext(), "YES",Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "NO",Toast.LENGTH_LONG).show();

Surprisingly it's showing
how! What mediastore gave me?? My main intention is to manipulate or convert the thumbnail image into base64 string. But
method was giving
File not exists
error so I tried to check the existence of the file.

Why is this giving me error like file not exists when filepath is given by the mediaStore. What's going on? What I'm missing? What's the way to manipulate/access thumbnail image?

Answer Source

I came across the same issue few days ago. The reason is due to some internal memory management process, sometimes it store images either in /storage/emulated/0/DCIM or /storage/emulated/1/DCIM.

To deal with this, its always recommended that Create your new folder for saving newly captured image from camera & access it from that folder.

Also, Check it on real device it may because there is no sd card for emulator & So it gets confused where to store if internal memory gets full so it jumps to sd card dcim folder.