If I have this in hand:
R.drawable.foo
Which is really just a reference to a jpg file, how do I open it in Android’s gallery app?
I have found a bunch of references which suggest something along the lines of this:
startActivity(
new Intent(
Intent.ACTION_VIEW,
/* what goes here for the URI?? */
)
);
But what URI do I use?
I’m doing this tutorial and want to open the images in the native Android app when tapped so I can get all that zooming, sharing, etc. for free.
If I can’t use a URI here (as suggested here), what should I do to load the image?
by design other applications cannot access your resources. its the same the otherway.
so you have two options.
Easyway:
copy your resource (manualy) to the sdcard and then sent the uri
this is how your URI might look
Environment.getExternalStorageDirectory()abstracts hard coding or mountthe
.cachewill be a hidden folder and if you don’t want your temp image to show up in gallery images then you need to create a .nomedia empty file in the.cachefolderyou might need to add the sdcard permission
the Hardway:
your need to implement a FileContentProvider using a ContentProvider
supply you custom URI and supply your file from your FileContentProvider.Open, you may need to implement
mimeand other methods aswell for thisUPDATE
you may also need to register your content provider in the manifest.
Android – open pdf in external application