开发者

Android Data paths

I am trying to make a file containing the folder res/raw so I can use listFiles() so I can index all the files in that folder... I tried using

File folderDirectory = new File("/data/data/com.soundboard/res/raw/");
file[] soundFiles开发者_开发知识库 = soundDirectoory.listFiles();

ListFiles returns null, I think, unless I am reading my debugging info wrong (the soundFiles path is null)

What am I doing wrong?


You could use cd /data/data/com.soundboard in adb shell to find there is no res/raw there.

Usually, res/raw in .apk should be static, so you could unzip .apk simply and find out what are in res/raw.


res/raw can not be opened as a File and used as a directory. There is no way to index the files in that folder.

EDIT: when you build your APK the contents of the res/raw directory are compiled into an efficient format. See How does the mapping between android resources and resources ID work? for more detail. The best you might be able to do is use reflection on your packages R.raw class and list all its fields: I've never seen this done, so whether it will actually work is anyone's guess.


Sounds like you should be using /assets and the AssetManager. It behaves exactly like a file system, so you can use list. The /assets and /res/raw serve much the same purpose, with the one big exception is that /assets can be accessed as a file system.

Otherwise as Femi mentioned, you could use reflection and get the fields for com.soundboard.R.raw. You could then iterate over those and generate file descriptors for each file there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜