[英]Is there a way for a Library to know the package name of the application using it?
Is there a way for any class in a library (could be activity, view or any other class that may have access to a "magic" method) to know or inquire the package name of the application using it?有没有办法让库中的任何 class(可以是活动、视图或任何其他可能有权访问“魔术”方法的class )使用它来了解或查询 ZEFE90A8E604A7C840E88D03A67F6B7D8 的名称?
If so, how?如果是这样,怎么做?
It would be great to have this ability at run-time, but having this ability in build/compile time would be good as well.在运行时拥有这种能力会很棒,但在构建/编译时拥有这种能力也会很好。
If you have a Context of the application (you can have that passed into your library in a constructor, for example), you can do this:如果您有应用程序的上下文(例如,您可以在构造函数中将其传递到库中),您可以这样做:
context.getPackageName();
EDIT: definitely not at build/compile time.编辑:绝对不是在构建/编译时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.