0

I have a few thousand image files in a directory structure. There are a few hundred different subdirectories and each directory contains 10 images named 1.png - 10.png...

How can I add these folders to my app and access these images? Assuming I want foo/bar/1.png?

In android it doesn't appear like you have a string path to your assets or raw directories so I have no clue how I would do this. Please don't tell me I have to zip them then unzip them out of assets.

4

2 回答 2

0

the path to access the android asset folder is :

file:///android_asset/filename

You should be able to access a folder with :

file:///android_asset/folder1/folder2/targetFolder/

Note that there is 3 '/' after 'file:'

于 2013-03-03T21:20:51.477 回答
0

In android it doesn't appear like you have a string path to your assets

Sure you do. getAssets().open("foo/bar/1.png") will give you an InputStream to that PNG file, assuming that your project has assets/foo/bar/1.png in it. You can then use BitmapFactory to read it in.

However, resources cannot exist in subdirectories. You could write a script on your development machine that flattens the structure (e.g., foo/bar/1.png into foo_bar_1.png), then put the renamed files into whichever res/drawable-NNNN/ directory is appropriate.

于 2013-03-03T21:26:42.957 回答