Reputation:
I want to get a file list in raw resource directory. just as open a file directory and get all files in that directory.
Maybe we can just call system command to do it. but I am not sure how to find the correct file path of the raw directory.
Upvotes: 4
Views: 3440
Reputation: 2085
You need this:
Field[] fields = R.raw.class.getFields();
for (int i = 0; i < fields.length - 1; i++) {
String name = fields[i].getName();
@RawRes int rawId = (Integer)fields[i].get(null);
// Do your thing here.
}
Hope it helps.
Upvotes: 10
Reputation: 8935
You can use below string to access files in that directory. e.g. if file test.mp4 is located at raw directory, you can access it with below string:
android.resource://com.example.package/raw/test
I am not sure if you can query all files in that directory!
Upvotes: 0