(原创 转载注明:
http://blog.csdn.net/zuomohuaer)
删除快捷方式:
否则会找不到程序;
一、创建快捷方式。
获取创建快捷方式的权限:
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
创建快捷方式:
Intent shortcutIntent = new Intent(getApplicationContext() , ShowActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Demo快捷方式");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.icon_t2));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
二、删除快捷方式。
获取删除快捷方式的权限:
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
删除快捷方式:
Intent shortcutIntent = new Intent(getApplicationContext() , ShowActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent deleteIntent = new Intent();
deleteIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
deleteIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Demo快捷方式");
deleteIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(deleteIntent);
三、启动快捷方式的模式。
点击快捷方式,模式是启动一个Intent,在原有栈的队列之上启动一个Activity。
可以使用如:
android:launchMode="singleTop"
等,来设置启动模式;
四、注意点。
需要设置被启动Activity为可探索模式,即:
android:exported="true"
否则会找不到程序;
五、附带源码。
http://download.csdn.net/detail/zuomohuaer/7857635