我想通过编程方式获得主屏幕启动器中所有安装的快捷方式的列表.
我已经在线发现了很多片段,但没有一个提供正确的输出
对于此代码段:
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
ArrayList intentList = new ArrayList();
Intent intent=null;
String launchers="";
final PackageManager packageManager=getPackageManager();
for(final ResolveInfo resolveInfo:packageManager.queryIntentActivities(shortcutsIntent, 0)) {
launchers=launchers+"\n"+resolveInfo.activityInfo.packageName;
intent=packageManager
.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
intentList.add(intent);
}
这只提供预置的快捷键,如联系人,浏览器等.不完全是在主屏幕中发现的.
而这段代码片段:
PackageManager pm = getPackageManager();
Intent i = new Intent("android.intent.action.MAIN");
i.addCategory("android.intent.category.HOME");
List lst = pm.queryIntentActivities(i, 0);
if (lst != null) {
for (ResolveInfo resolveInfo : lst) {
}
}
}
只提供com.android.launcher的默认启动器.