简体   繁体   English

如何在Android中以编程方式检索自己的app-uri?

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

相关问题 如何让我的Android应用程序持续与我自己的RESTful API连接以连续检索数据? - How do I keep my Android app continuously connected with my own RESTful API to retrieve data continuously? 如何将 Firebase 中的图像检索到我的 android 应用程序中? - How do i retrieve images from Firebase into my android app? 如何在Android应用程序中获取SQLite数据库的URI? - How do I get the URI of my SQLite database in my Android app? 如何以编程方式删除自己的自定义损坏日历? - How do I delete my own custom corrupted calendar programmatically? 如何以编程方式“重启” Android 应用程序? - How do I programmatically "restart" an Android app? 如何以编程方式获取自己的Android应用统计数据? - How to get own Android app statistics programmatically? 在发生某个事件后,如何通过自己打开并使用另一个Android应用程序? - How do I open and use another android app through my own after a certain event? 我需要自己的网站来发布我的Android应用程序吗? - Do I need a own website to publish my Android app? Android - 如何在不付费的情况下下载自己的付费应用? - Android - how do I download my own paid app without paying? 如何提交我自己的 Android 应用按钮和字符串翻译? - How do I submit my own translations for Android app buttons and strings?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM