Android 库从调用者的清单文件中读取
Android 开发新手,并询问以下方面的最佳实践。
我正在为多个应用程序构建一个库。我用于库调用的参数之一是应用程序名称。我可以从父配置文件中选取它来清理 api 接口,这样就不再需要它了?我对传递上下文有同样的问题,但我想由于安全原因这可能并不那么容易。
如果您可以读取调用者配置,那么下一个问题是我是否可以要求将此 appname 参数添加到调用者清单中?
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'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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android 中没有“配置文件”这样的概念。如果您的意思是“清单文件”(根据您的标题),那么您通常无法真正读取清单文件。
让托管应用程序传入此值,或者让托管应用程序传入其包名称(以便您可以在
PackageManager
中查找此信息),或者从Context 获取包名称托管应用程序传入的
(因此您可以使用PackageManager
)。需要什么“将其添加到调用者清单中”?包名称已经存在。应用程序的
android:label
已经存在 - 您可以从PackageManager
获取它。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 aContext
that the hosting application passes in (so you can usePackageManager
).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 fromPackageManager
.