android - 在 Android 9.0 中创建进入主屏幕的快捷方式
问题描述
我使用以下代码创建快捷方式
private void createShortCut() {
Intent shortcutIntent = new Intent(getApplicationContext(), SplashActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate", false);
getApplicationContext().sendBroadcast(addIntent);
}
上面的代码在 android 7.0 中运行良好,但在 android 8.0 及更高版本中不起作用。如何在 android 8.0 及更高版本的主屏幕中添加快捷方式?
解决方案
请参考这篇文章:
https
://developer.android.com/guide/topics/ui/shortcuts/creating-shortcuts你应该使用ShortcutManager
这个目的。
推荐阅读
- browser-sync - 使用 browsersync 时无法从移动设备访问 http://192.168.56.1:3000
- spring-batch - 如何在 Spring Batch 中从二进制文件中读取数据
- android - 在 Android 上找不到保存的 CSV 或 TXT 文件
- ruby-on-rails - 如何将 ruby 逻辑插入到 erb 文件中 div 标签的样式属性中?
- typescript - typecirpt 我如何定义 ...props 接口?
- python - 如何将python嵌套字典转换为非嵌套字典?
- powershell - 当它之后有另一个 GET 时,GET 不打印?
- google-calendar-api - 通过 API 创建的事件未在打印中列出
- python - 如何使用 keras 将 LSTM 模型转换为线性回归?
- java - 进行邮件合并后样式不保留(包括字体大小、字体粗细、字体颜色……)