[原理]
1. 系统有一个BroadcastReceiver 其action = "com.android.launcher.action.INSTALL_SHORTCUT" 用于接收与快捷方式有关的Intent
2. 我们要做的就是:把快捷方式的有关信息装入对应的Intent 然后发送出去即可
[代码]
1. 定义对应的Intent
- private final String ACTION_ADD_SHORTCUT =
- "com.android.launcher.action.INSTALL_SHORTCUT";
- Intent intent = new Intent(ACTION_ADD_SHORTCUT);
2. 把有关信息装入Intent 比如 图标 名字 其所引起的Intent
- Intent dial = new Intent(Intent.ACTION_CALL);
- dial.setData(Uri.parse("tel://110"));
- intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Dial to 110");
- intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,dial);
- intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
(当按下该快捷方式后 就会拨打110)
3. 发送之
- sendBroadcast(intent);