Shri
Shri

Reputation: 1243

Accessing assets in subdirectories in android?

I'm reusing my iphone resources, I have myriads of resources which have many subdirectories I'm reusing much of native code aswell, I understand that to open assets we MUST provide relative path for ex if I have file name test1.png in assets/subdir1/subdir2/subdir3/test1.png I have to mention whole of the relative path, As I already said I'm using much of native code so is there any way I can just access asset files using just the filename without full relative path "test1.png"? Or if this is not possible is there anyway we can logically structure our resources but the folder name actually doesn't exist physically.

Upvotes: 1

Views: 2559

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006614

I understand that to open assets we MUST provide relative path for ex if I have file name test1.png in assets/subdir1/subdir2/subdir3/test1.png I have to mention whole of the relative path

With AssetManager and methods like open(), you would not have the assets/ portion of the relative path. In your example, you would use open("subdir1/subdir2/subdir3/test1.png").

As I already said I'm using much of native code so is there any way I can just access asset files using just the filename without full relative path "test1.png"?

Of course not. You might have 10,000 files named test1.png in your entire assets/ tree -- we need to know which of those to open.

Moreover, AFAIK, native code has no access to assets.

Or if this is not possible is there anyway we can logically structure our resources but the folder name actually doesn't exist physically.

Whatever you physically put as your directory tree in assets/ in your project is what you will need to use when accessing them through AssetManager. If you do not want to have to deal with subdirectories with AssetManager, do not create subdirectories inside of assets/

Upvotes: 5

Related Questions