桌面快捷图标(shortcut)
步骤:
1、你要做什么
2、你叫什么名字
3、你长什么样子
原理:发送一个广播,当桌面程序接受到该广播后自动在桌面上创建一个快捷图标
该广播所携带的内容:快捷图标的名称、名称以及点击该图标时的意图
代码:
Intent intent = new Intent();
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, 名称);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, 图标);
//点击时的意图即响应什么事件
Intent newIntent = new Intent();
newIntent.setAction(Intent.ACTION_MAIN); //Intent.ACTION_MAIN标识一个程序的入口,即最先启动的activity
newIntent.addCategory(Intent.CATEGORY_LAUNCHER); //Intent.CATEGORY_LAUNCHER 决定程序是否显示在程序列表中
newIntent.setClassName(getPackageName(), 启动页面的在包中的具体路径);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newIntent);
sendBroadcast(intent);