获取手机上的所有应用的包名类名(包括系统应用)
以下代码直接可以使用
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addequipment_activity);
loadApps();
}
private List<ResolveInfo> resolveInfo= new ArrayList<>();
private void loadApps() {
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
resolveInfo= getPackageManager().queryIntentActivities(intent, 0);
//for循环遍历ResolveInfo对象获取包名和类名
for (int i = 0; i < resolveInfo.size(); i++) {
ResolveInfo info = resolveInfo.get(i);
String packageName = info.activityInfo.packageName;
CharSequence cls = info.activityInfo.name;
CharSequence name = info.activityInfo.loadLabel(getPackageManager());
String parentActivityName = info.activityInfo.parentActivityName;
Log.e(TAG, "打印-- :" + name + "----" + packageName + "----" + cls);
}
}