I have this app installed in my device (Nexus s).
It caches some images if you use this app. This is why it shows cached images in my device’s gallery.
I use cursor to get the path
final String[] columns = { MediaStore.Images.Media.DATA };
Cursor imagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns,
MediaStore.Images.Media._ID + " = " + id, null, MediaStore.Images.Media._ID);
if (imagecursor != null && imagecursor.getCount() > 0){
imagecursor.moveToPosition(0);
String path = imagecursor.getString(imagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
Log.d("path", path);
File f = new File("file://" + path);
Log.d("check_file", "" + f.exists());
}
I get the path:
/mnt/sdcard/cache/hk.ignition.podcast/cartoon/2/http%3A%2F%2Fbigcity.learnenglishapps.com%2Fimages%2Fcartoons%2Fset2%2Ffast-food-new-1.png
Downloaded image is:
http://bigcity.learnenglishapps.com/images/cartoons/set2/fast-food-new-1.png
When I pull the file or explore it with file manager like Astro, its there.
But when I check if file exist, then it says false.
Is there any character issue?
Update:
Removing file:// worked to check if file exist.
Next is, I’d like to open that file in gallery.
- should I use this path to open image?
But that not worked:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file:///mnt/sdcard/cache/hk.ignition.podcast/cartoon/2/http%3A%2F%2Fbigcity.learnenglishapps.com%2Fimages%2Fcartoons%2Fset2%2Ffast-food-new-1.png"),
"image/*");
startActivityForResult(intent, 3);
- Or I should try to get
content://style path from MediaStore?
Update 2:
Solved using :
Uri.fromFile(f);
Instead of Uri.Parse(). As it builds / character from encode format.
Change
new File("file://" + path)to justnew File(path)