1

我试过这个:

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

此代码为我提供了已安装应用程序包名称等的列表。但我只想要应用程序名称作为字符串类型列表。我该怎么办?

4

1 回答 1

3

您可以使用以下代码 ::: 请参阅此链接

public class AppList extends Activity {
  ....
  private ArrayList results = new ArrayList();
  @Override
  public void onCreate(Bundle savedInstanceState) {
    .....
    PackageManager pm = this.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    List list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
    for (ResolveInfo rInfo : list) {
       results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
       Log.w("Installed Applications", rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
  } 
 }
}

在上面的代码中“结果”是安装的数组列表应用程序

于 2012-04-22T07:25:48.970 回答