本文共 977 字,大约阅读时间需要 3 分钟。
在清单文件下,将要设置快捷启动的Activity添加intent-filter
属性
AndroidManifest.xml
/** * 创建快捷图标 * * @param view view */public void createShortcutIcon(View view) { Toast.makeText(this, "创建快捷图标", Toast.LENGTH_SHORT).show(); String title = "第二页"; Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); Intent intent = new Intent(this, Main2Activity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // 添加Intent Intent createShortcutIconIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); // 标题 createShortcutIconIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title); // 图标 createShortcutIconIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon); // Intent createShortcutIconIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); // 发送广播创建图标 sendBroadcast(createShortcutIconIntent);}