http://viralpatel.net/blogs/android-install-uninstall-shortcut-example/:
Android com.android.launcher.action.INSTALL_SHORTCUT, . MainActivity HelloWorldShortcut.
INSTALL_SHORTCUT android manifest xml.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
addShortcut() .
private void addShortcut() {
Intent shortcutIntent = new Intent(getApplicationContext(),
MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.ic_launcher));
addIntent
.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
, shortcutIntent, . EXTRA_SHORTCUT_INTENT. . ,
EXTRA_SHORTCUT_NAME , EXTRA_SHORTCUT_ICON_RESOURCE.
. , , , android: exported = "true" .
:
, Android Intent (UNINSTALL_SHORTCUT) . , .
. Android manifest xml.
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
removeShortcut() addShortcut(). , removeShortcut UNINSTALL_SHORTCUT.
private void removeShortcut() {
Intent shortcutIntent = new Intent(getApplicationContext(),
MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent
.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
addIntent
.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}