Creating a URI for an Android Resource
@kylewbanks on Mar 15, 2013.
Written by Hey, if you didn't already know, I'm currently working on an open world stealth exploration game called Farewell North in my spare time, which is available to wishlist on Steam!
When using resources in an Android application, it is usually sufficient to make use the of resource manager with functions such as getString() and getDrawable(). Occasionally however, you will need to get the actual URI of a resource.
The process is very easy, as the URI has a very sensible setup:
android.resource://[package-name]/[Resource-ID]
All you need to do is replace the package name with your app's package name, as defined in the manifest, and the resource ID of the resource you would like to use.
Uri resourceURI = Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.my_resource);
Let me know if this post was helpful on Twitter @kylewbanks or down below!