Get path of Android resource

Prime picture Prime · Jun 10, 2011 · Viewed 78.7k times · Source

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.

Answer

HPP picture HPP · Oct 24, 2013

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)