从Android包名称获取应用程序名称名称、应用程序、Android

2023-09-06 10:12:45 作者:桃凌。

我想开发一款Android应用,可以列出所有的应用程序的有缓存,我顺利地拿到了有关高速缓存的信息,但现在我想显示其有一定的缓存在屏幕的应用程序,我有包名的,但问题是如何从包名称获取应用程序名称,

I'm trying to develop an android app that could list all app's which has cache, I successfully got the information about cache, but now I want to display those app which has some cache in the screen, I have the package name, but problem is how to get the application name from package name,

让我们说包名称为 com.android.browser 那么应用程序的名称将是浏览器

如何实现这一任务?

请不要介意,如果这个问题是愚蠢的你,请帮我解决这个谜团,先谢谢了。

Please don't mind if this question is silly to you, please help me in solving this riddle, Thanks in advance.

推荐答案

您需要使用软件包管理系统来获取有关安装软件包的详细信息。

You need to use PackageManager to get detailed information about installed packages.

PackageManager packageManager = context.getPackageManager();
ApplicationInfo applicationInfo;
try {
    applicationInfo = packageManager.getApplicationInfo(packageName, 0);
} catch (final NameNotFoundException e) {}
final String title = (String)((applicationInfo != null) ? packageManager.getApplicationLabel(applicationInfo) : "???");
 
精彩推荐
图片推荐