简体   繁体   English

图书馆有没有办法知道使用它的应用程序的 package 名称?

[英]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.

相关问题 如何知道用户正在使用的应用程序名称? - How to know the application name which the user was using? 在Android应用程序包名称中使用特殊字符 - Using special characters in an Android application package name 使用包名称获取应用程序信息 - Fetching Application info By using its package name 命名正在运行的应用程序而不是程序包名称 - Name running application and not package name 如何使用其他应用程序包名称将图像设置为按钮? - How to set an image to the button using the other application package name? 使用Maven在Eclipse Java Web应用程序中的组ID和程序包名称 - Group Id and package name in Eclipse java web application using maven 如何使用Java的HTTP客户端库设置应用程序名称? - How to set the application name using the HTTP Client Library for Java? 错误:包装 <package name> 不存在-但我知道吗? - Error: package <package name> does not exist - but I know it does? 有没有一种方法可以在不使用Servlet功能的情况下获取Web应用程序的名称? - Is there a way to get the name of web application without using Servlet features? 不止一个带有包名的库 - More than one library with package name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM