【问题标题】:How to get class name from package name in android?如何从android中的包名中获取类名?
【发布时间】:2013-03-14 21:31:30
【问题描述】:

我想分别列出已安装和系统应用程序。下面是我的代码

List<ApplicationInfo> appList = packageManager.getInstalledApplications(0);
if(appList != null && !appList.isEmpty()){
        for (ApplicationInfo appInfo : appList) {
        Intent intent = packageManager.getLaunchIntentForPackage(appInfo.packageName);
        if(intent != null){
            ComponentName componentName = intent.getComponent();
            if((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
                //It is a system app
            }else{
                //It is an installed app.
            }
        }
    }
}

我想在点击 listview 时启动每个应用程序。但 componentName .getClassName() 对某些人显示为“com.android.internal.app.ResolverActivity”联系人、地图等应用程序...如何获得此类应用程序的确切类名。我无法使用 ResolveInfo,因为很难对应用程序进行分类。

如何使用包名获取应用程序的准确类名?

提前致谢

【问题讨论】:

  • 我在运行 4.2.2 的 Galaxy Nexus 上运行了您的示例代码,但没有安装任何显示为 ResolverActivity 的应用程序。你能给我们多介绍一点背景吗?你在做什么?也许这不是您回答的直接途径...但是您让我很好奇为什么您会看到 ResolverActivity 而我没有。
  • 我用的是 Galaxy Tab 2.2

标签: android class-names


【解决方案1】:

你可以问packageManager:

CharSequence label = "";
for (ApplicationInfo appInfo : appList)    
    label = packageManager.getApplicationLabel(appInfo);

【讨论】:

  • packageManager.getApplicationLabel() 返回应用的名称。我要获取类名
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-31
  • 2012-01-28
  • 1970-01-01
  • 2020-03-19
  • 1970-01-01
  • 1970-01-01
  • 2012-04-01
相关资源
最近更新 更多