如何从android中的包名获取类名?

时间:2013-03-25 11:47:47

标签: android class-names

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

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 ,因为很难对应用程序进行分类。

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

先谢谢

1 个答案:

答案 0 :(得分:-1)

您可以询问packageManager:

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