思路:
获得手机上应用列表,同时获得应用的图标、应用名、包名信息。
代码如下(简单的listview+获得应用列表信息,布局文件不给出):
public class InstallActivity extends AppCompatActivity { ListView lView; List<String> results = new ArrayList<String>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_uninstall_warning); lView = (ListView) findViewById(R.id.list_view); 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()); pm.getApplicationIcon(rInfo.activityInfo.applicationInfo);//获得应用的图标 pm.getApplicationLabel(rInfo.activityInfo.applicationInfo).toString();//获得应用名 String a = rInfo.activityInfo.applicationInfo.packageName;//获得应用包名 Log.e("InstallActivity","包名:"+a); } lView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results)); } }最主要的是pm.getApplicationIcon(rInfo.activityInfo.applicationInfo);//获得应用图标
pm.getApplicationLabel(rInfo.activityInfo.applicationInfo).toString();//获得应用名称
rInfo.activityInfo.applicationInfo.packageName;获得应用包名