My question is: is it possible to get the absolute path of a resource (in a subdirectory of the res/ folder) in Android?
Most of the answers I see to this question on google suggest getting a file descriptor, implying that this is not possible.
Is it?
EDIT: The reason I want to do this is because I'm writing classes that accept a path to media and play it. Testing would be much easier if I could pass the absolute path of a resource.
The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.
The resources locates inside res directory of your app. The Android resource compiler processes resources arcording to which subforder they are in and the format of the file, for example: res/drawable : Contains all resources file that can be drawable, such as (. png, .
Use URI Paths instead of "absolute" path, see this post
Uri path = Uri.parse("android.resource://com.segf4ult.test/" + R.drawable.icon); Uri otherPath = Uri.parse("android.resource://com.segf4ult.test/drawable/icon");
Or use openRawResource(R.id) to open an inputStream, and use it the same way you would use a FileInputStream (readonly)
Not possible. The resource folder you see is compiled into the apk, and it may not even store as it is. (e.g. those layout xml files are no longer xml files once it is compiled)
Two possible solution/work-around for your situation:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With