想要在手机的桌面上添加快捷方式,而桌面又属于系统的应用,也就是说我们需要有一个与系统进行通信的接口。还好Android中有广播,而Android系统中又有接收添加快捷方式广播的广播接收者。于是,为我们的应用快捷方式就变得很简单了。
private void createShortCut() {
Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
// 获取快捷键的图标
Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.short_cut_icon);
Intent myIntent = new Intent(this, ShortCutActivity.class);
// 快捷方式的标题
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷方式");
// 快捷方式的图标
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
// 快捷方式的动作
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);
// 发送广播
sendBroadcast(addIntent);
}
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
http://zhushou.360.cn/detail/index/soft_id/2419729?recrefer=SE_D_%E6%A3%B1%E9%95%9C
http://www.wandoujia.com/apps/com.mastershield.personalstat
原文:http://blog.csdn.net/lemon_tree12138/article/details/42371119