Creating a URI for an Android Resource
@kylewbanks on Mar 15, 2013.
Written by Hey! 👋 I recently left my job as a software engineer to become a full-time indie game developer. After four years of development you can find my first game, Farewell North, on Xbox, Nintendo Switch, and 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!