h4lc0n
h4lc0n

Reputation: 2770

Android app accessing library resources

The project I'm working on requires that N stand-alone applications can be built but also an extra big application with a selection menu that will execute one of those.

The difference between these applications is mainly resources and XML, so they all use a common library which reacts to assets and the information provided in the XML.

The problem is regarding the "mother" application. It has to be able to use the common library using one of the stand-alone resources set. I realized I can access another application resources using:

Resources R2 = getPackageManager().getResourcesForApplication("com.example.appa");
int id = R2.getIdentifier("image", "drawable", "com.example.appa");
Drawable myDrawable = R2.getDrawable(id);

And this actually solves the issue, I can supply a package string to the library so it will know where to look for the resources.

Problem is, in order for this to work, I need to have those stand-alone applications installed on the device, and that's something I cannot do (think of it as a quiz application, the stand-alone apps are only one topic while the "mother" app allows access to all different topics and, as far as I'm aware, Android Market won't allow downloading all apps and installing them just so I can access their resources).

Conceptually speaking, this issue would be solved if I could make those stand-alone applications as libraries and adding them to the mother app. The mother app would then use a package string depending on user choice and then use the library. So far I haven't been able to work this out and I can't find information about this so I'm afraid this can't be done.

Each topic application has, for example, an intro.png with an image regarding the topic of the app (for example a roman or a greek image) and the idea is to access package_string.intro.png so it will automatically access the right one depending on user choice.

Upvotes: 3

Views: 1010

Answers (1)

h4lc0n
h4lc0n

Reputation: 2770

After struggling to do this I finally found out resources are indexed which means only one "intro.png" exists in one application, no matter how many libraries you try to link, you can't create a reference to lib1.intro.png or lib2.intro.png. I finally built a resource manager system which works with "lib1_intro" or "lib2_intro" on demand. Not the cleanest of solutions but, meh, it works I guess...

Moving my edit to an answer as I read about accepting answers and this is how it should have been done instead of just editing my first post

Upvotes: 2

Related Questions