PackageManager的applicationInfo.name始终为null
PackageManager pm = this.getPackageManager();
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses();
for(RunningAppProcessInfo process : runningAppProcesses) {
try {
ApplicationInfo ai = pm.getApplicationInfo(process.processName, PackageManager.GET_META_DATA);
Log.d(TAG, applicationInfo.name + "");
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
process.processName
返回有效的包名称,但 applicationInfo.name
始终为 null。
PackageManager pm = this.getPackageManager();
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningAppProcesses = am.getRunningAppProcesses();
for(RunningAppProcessInfo process : runningAppProcesses) {
try {
ApplicationInfo ai = pm.getApplicationInfo(process.processName, PackageManager.GET_META_DATA);
Log.d(TAG, applicationInfo.name + "");
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
process.processName
returns a valid package name but applicationInfo.name
is always null.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
applicationInfo.loadLabel(packageManagerInstance)
查找应用程序名称,但applicationInfo.name
不起作用应该是有原因的。Edit
applicationInfo.name
是Application
子类的名称(如果有的话)。Used
applicationInfo.loadLabel(packageManagerInstance)
to find the Application name, but there should be a reason whyapplicationInfo.name
didn't work.Edit
applicationInfo.name
is the name of aApplication
subclass if you have any.名称为 null 的原因是它确实是... null。
请参考Android清单文档:
您想要的是应用程序的名称,该名称在应用程序标签的 label 属性中设置,Ragunath 解释了如何获取该名称。
The reason name is null is that it really is... null.
Please refer to the Android manifest documentation:
What you want is the name of the application, which is set in the label attribute of the application tag, and which Ragunath explained how to get.
试试这个
或这个
Try this
or this