Reputation: 2391
I couldn't find how to list all drawable inside another app from my app.
I managed to get drawables if I know the name, but couldn't find how to do it with a simple loop from 1 to N.
Any of you could offer a code template to do this?
The following code already works:
mAndromedaAddonContext = createPackageContext( "com.demo.andromeda",
Context.CONTEXT_IGNORE_SECURITY );
mPlanetsResID[0] = mAndromedaAddonResources.getIdentifier( "planet20111007081421628", "drawable", "com.demo.andromeda" );
But I want to iterate without using the resource name. Something along those lines: for(int i=0; i
I do have the same sharedUserId and process in the manifest file, so I have the privilege to access the resources from the other app.
Thanks in advance.
Upvotes: 2
Views: 594
Reputation: 20553
First use mAndromedaAddonResources.getAssets()
to get an instance of AssetManger for the app you are targeting.
see here: https://developer.android.com/reference/android/content/res/Resources.html#getAssets()
Then you can use the
public final String[] list (String path)
method in AssetManager class to get a list of all assets at a given path( In your case, it would be the path of the res/drawable folder for the app you are targeting). This will give you a list of strings where each string is an asset name. Then you can simply use the same code you are using to obtain their identifiers.
For more info on AssetManager: https://developer.android.com/reference/android/content/res/AssetManager.html
Upvotes: 2