On Android 4.2.2, Intent INSTALL_SHORTCUT creates shortcut in the second page -
i strange result when calling code create shortcut in home screen.
the shortcut is created on second page of home screen (and first page empty there enought space!). ideas?
public static void installshortcut(context context, string packagename, string componentname, string shortcutname, parcelable icon) { intent shortcut = new intent("com.android.launcher.action.install_shortcut"); componentname cn = new componentname(packagename, componentname); shortcut.putextra(intent.extra_shortcut_intent, new intent(intent.action_main).setcomponent(cn)); shortcut.putextra(intent.extra_shortcut_name, shortcutname); shortcut.putextra(intent.extra_shortcut_icon_resource, icon); shortcut.putextra("duplicate", false); context.sendbroadcast(shortcut); } // gets info external package name public static void createshortcutforpackage(context context, string packagename, string classname) { intent intent = new intent(); intent.setcomponent(new componentname(packagename, classname)); packagemanager pm = context.getpackagemanager(); resolveinfo ri = pm.resolveactivity(intent, 0); string shortcutname = ri.loadlabel(pm).tostring(); string activityname = ri.activityinfo.name; int iconid = ri.activityinfo.applicationinfo.icon; context pkgcontext; try { pkgcontext = context.createpackagecontext(packagename, context.context_include_code | context.context_ignore_security); if (pkgcontext != null) { shortcuticonresource sir = intent.shortcuticonresource.fromcontext(pkgcontext, iconid); installshortcut(pkgcontext, packagename, activityname, shortcutname, sir); } } catch (namenotfoundexception e) { } }
this default android 4.2.2 home screen:
update: on android 4.0.4 shortcut created in right place.
there hundreds of home screen implementations, both pre-installed , ones installable via play store. each welcome either:
- ignore
intent
entirely, not having<intent-filter>
it, or - put shortcut wherever wants
on android 4.0.4 shortcut created in right place.
no, put in "the right place" in both cases, authors of home screen -- not -- determines "the right place" is.
Comments
Post a Comment