user2575413
user2575413

Reputation:

get file list in android raw resource directory from code

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

Answers (2)

Junior Buckeridge
Junior Buckeridge

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

lucky1928
lucky1928

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

Related Questions