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