android - 如何在 android oreo(8.0) 上将应用程序启动器图标添加到主屏幕?

标签 android icons shortcut launcher

我正在 Android 8.0 上制作一个 Android 应用程序。我已经在 Using Static Shortcuts 阅读过快捷方式的开发文档 但此文档没有方法将启动器图标添加到主屏幕。

我用过8.0之前的方法:

Intent i= new Intent(Intent.ACTION_MAIN);  
i.addCategory(Intent.CATEGORY_LAUNCHER);

Intent intent = new Intent();     
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i);     
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, 
context.getResources().getString(R.string.app_name));       
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 
Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
intent.setAction(com.android.launcher.action.INSTALL_SHORTCUT);
context.sendBroadcast(intent);

如何将应用程序图标添加到主屏幕? 谢谢。

最佳答案

如 Android 开发者所述

The com.android.launcher.action.INSTALL_SHORTCUT broadcast no longer has any effect on your app, because it is now a private, implicit broadcast. Instead, you should create an app shortcut by using the requestPinShortcut() method from the ShortcutManager class.

查看此链接 Android 8.0 Behavior Changes

关于android - 如何在 android oreo(8.0) 上将应用程序启动器图标添加到主屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46842984/

相关文章:

c++ - 如何获得在 C++ 中生成字母表的更简单方法?

java - 仅用于在页面上搜索的 Eclipse 快捷方式

android - 无法从 ubuntu/linux 远程调试 android/chrome

java - 错误 : Executing command 'ant' , 请确保您已安装 ant 并将其添加到您的路径

java - 为什么未选择的 JButton 显示突出显示的图标?

url - .url 文件不加载图标

c++ - 二维数组值 C++

android - 如何重写 Fragment 中的 AttachBaseContext?

android - 无法在 Android 中使用 OpenCV VideoCpature java 类打开视频文件

eclipse - 有没有办法更改 Eclipse 内置的默认 Eclipse 工具栏图标?