android获取已安装的应用程序包名和类名

来源:互联网 发布:js match 正则 编辑:程序博客网 时间:2024/05/29 08:43

plintPkgAndCls(getResolveInfos());


private void plintPkgAndCls(List<ResolveInfo> resolveInfos){
for (int i = 0; i < resolveInfos.size(); i++) {
String pkg = resolveInfos.get(i).activityInfo.packageName;
String cls = resolveInfos.get(i).activityInfo.name;
Log.i(TAG, "packageName = " + pkg);
Log.i(TAG, "name = " + cls);
}
}

private List<ResolveInfo> getResolveInfos(){
List<ResolveInfo> appList = null;

Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager pm = getPackageManager();
appList = pm.queryIntentActivities(intent, 0);
Collections.sort(appList, new ResolveInfo.DisplayNameComparator(pm));

return appList;
}

原创粉丝点击