1

I've a android library which is called from an App. I want to access App's version from library project. Is it possible at all?

EDIT: I don't control the calling app. I need some way to get calling app's version from library.

2 Answers 2

3

If you pass the context information, you should be able to use

PacketManager yourPacket = context.getPackageManager(); 

which gives you oodles of information.

Sign up to request clarification or add additional context in comments.

7 Comments

This solution works for at the App level, which has context. But my library doesn't have any activity of its own. Is it possible to retrieve version from Android Manifest for such standalone library?
the problem is: by itself, the library doesn't "exist". You'd have to embed version information into it or use the App's context so it starts searching information about associated Packets.
you could, for instance, require the App to instance your class with its Context and use said context to reference its information.
Actually, I need to keep App version independent of library's version. Do you think I've to make library's version hardcoded in form of constant or something like that in library's code?
You can't force the App that's calling you to provide you with a Context reference? That would be the best way, actually.
|
1

One option you have to is get the apps version from your own app itself, and then make it available "manually" to the library by storing it in some sort of shared storage like a WORLD_READABLE file, or on the SDcard or something.

Or perhaps depending on the library, and how much you are able to modify it you could also use some sort of Static object to hold the data for you.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.