Android Library read from caller's manifest file
New to android development and asking for best practices around the following.
I am building a library for multiple apps. One of the parameters I have for the library calls is the appname. Can I pick this up from a parent config file to clean up the api interface so it'开发者_StackOverflow社区s not required everywhere? I have the same question around passing around the Context but I guess that might not be as easy due to security reasons.
If you can read the callers config, the next question is can should I require this appname parameter to be added this to the callers manifest?
Can I pick this up from a parent config file to clean up the api interface so it's not required everywhere?
There is no such concept as a "config file" in Android. If you mean "manifest file" (per your title), then you can't really read the manifest file in general.
Either have the hosting application pass in this value, or have the hosting application pass in its package name (so you can look this information up in PackageManager
), or get the package name from a Context
that the hosting application passes in (so you can use PackageManager
).
the next question is can should I require this be added this to the callers manifest?
Require what to "be added this to the callers manifest"? The package name is already there. The android:label
for the application is already there -- you get this from PackageManager
.
精彩评论