How can I get the URI of image saved in drawable. I have tried following formats, but everytime it cannot load the image.
imageURI= Uri.parse(\"android.resou
You can also try this:
Bitmap bm = BitmapFactory.decodeResource( getResources(), R.drawable.myimage_name);
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File file = new File(extStorageDirectory, "MyIMG.png");
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Uri imguri=Uri.fromFile(file);
Try this:
Resources resources = context.getResources();
Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resId) + '/' + resources.getResourceTypeName(resId) + '/' + resources.getResourceEntryName(resId) );
I found most of the answers confusing for a novice user so i am including an example.
your_package_name = org.xyz.abc
image in drawable is => myimage.jpg
Uri uri = Uri.parse("android.resource://org.xyz.abc/drawable/myimage");
or
Uri uri = Uri.parse("android.resource://"+context.getPackageName()+"/drawable/myimage");
This is what you really need:
Uri imageUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + getResources().getResourcePackageName(R.drawable.ic_launcher)
+ '/' + getResources().getResourceTypeName(R.drawable.ic_launcher) + '/' + getResources().getResourceEntryName(R.drawable.ic_launcher) );