开发者

Is there a way for a Library to know the package name of the application using it?

开发者 https://www.devze.com 2023-03-18 05:49 出处:网络
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 applicatio

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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消