[英]How do i retrieve my own app-uri programmatically in android?
Is there a way to get it through the context file or the package-manager? 有没有办法通过上下文文件或程序包管理器来获取它? Have searched for it but didn't find anything. 搜索过,但没有找到任何东西。
Just call getPackageName() on your context. 只需在您的上下文中调用getPackageName()即可 。 You can call this in any Activity, Service, or basically anything that inherits from Context . 您可以在任何Activity,Service或基本上从Context继承的任何东西中调用它。
Other than that, if you want to access it somewhere without a context, just create a separate class to hold preknown values like this: 除此之外,如果您想在没有上下文的地方访问它,只需创建一个单独的类来保存这样的先验值即可:
public class MyConstants {
public static final String PACKAGE_NAME = "com.my.package";
}
and then access it anywhere in your app using MyConstants.PACKAGE_NAME
wherever you need it. 然后在需要的地方使用MyConstants.PACKAGE_NAME
在应用程序中的任何位置访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.