[英]How to obtain package name of an application in Android?
I want to display package name of an application in a BroadcastReceiver
whose intent
is received in that receiver
. 我想在
BroadcastReceiver
显示应用程序的程序包名称,其intent
是在该receiver
。 I used the intent.getPackage()
method but it is not working. 我使用了
intent.getPackage()
方法,但是它不起作用。 I also tried to display that package name using context object which is a parameter of onReceive()
method to display package name but it is not working. 我还尝试使用上下文对象显示该软件包名称,该上下文对象是
onReceive()
方法的参数,用于显示软件包名称,但是它不起作用。
Please help me. 请帮我。 Thanks in advance.
提前致谢。
This way : 这条路 :
ApplicationInfo packageInfo = this.getApplicationContext().getApplicationInfo();
packageName = packageInfo.packageName;
EDIT : This is not working from a broadcast receiver, I misread the question. 编辑:这不能从广播接收器,我读错了问题。
Reading this page : http://developer.android.com/reference/android/content/Intent.html Intent.getPackage doesn't give you the package that called but the one that the intent is limited to. 阅读此页面: http : //developer.android.com/reference/android/content/Intent.html Intent.getPackage不会给您调用的包,而是给您提供意向性限制的包。
If I understand this page clearly, Intents do not provide the package name or anything allowing you to identify it. 如果我清楚地了解此页面,则Intent不提供程序包名称或任何允许您识别的名称。
If you are the one sending the intent(but I believe you are not), you could send the package name in the intent in a parcelable that you'd be able to retrieve in your broadcast receiver. 如果您是发送意图的人(但我相信您不是),则可以将意图中的包裹名称发送到可在广播接收器中检索到的包裹中。 Otherwise, I don't think it is possible.
否则,我认为不可能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.