I wanted to get the list of all installed shortcuts in the homescreen launcher programmatically. I have found lots of snippets online but none of them provides the right output
for this snippet:
Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
ArrayList<Intent> intentList = new ArrayList<Intent>();
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);
}
this only provides the preset shortcuts like contacts, browsers,etc. not exactly what is found in the homescreen.
while this snippet:
PackageManager pm = getPackageManager();
Intent i = new Intent("android.intent.action.MAIN");
i.addCategory("android.intent.category.HOME");
List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
if (lst != null) {
for (ResolveInfo resolveInfo : lst) {
}
}
}
only provides the default launcher which is com.android.launcher.
My answer may be late, but it might be useful for others.
Check my code:
if (Build.VERSION.SDK_INT <8)
{
url = "content://com.android.launcher.settings/favorites?Notify=true";
}
else
{
url = "content://com.android.launcher2.settings/favorites?Notify=true";
}
ContentResolver resolver = getContentResolver();
Cursor cursor = resolver.query (Uri.parse(url), null, null, null, null);
来源:https://stackoverflow.com/questions/12738865/how-to-get-the-list-of-all-installed-shortcuts-found-in-the-homescreen-launcher