[小代码]获得已安装应用程序的列表

列出所有已安装的应用程序:

   ListView lView;
   List<String> results = new  ArrayList<String>();
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    lView = (ListView) findViewById(R.id.listView1);

    PackageManager pm = this.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);

    for (ResolveInfo rInfo : list) {
        results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
    }

    lView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
  }



你可能感兴趣的:(android,列表,应用程序,已安装)