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

问题描述:

我正在Android 8.0上制作Android应用程序。我已阅读开发文档的快捷方式在Using Static Shortcuts 之前更改,但此文档没有方法添加启动器图标到主屏幕。如何将应用程序启动器图标添加到android oreo(8.0)的主屏幕上?

我已经使用方法: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); 

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

+0

是,面临同样的问题:( –

作为Android开发者

的com.android.launcher.action.INSTALL_SHORTCUT广播不再对您的应用程序没有任何影响,因为它现在是一个私人的,隐含的广播提及。相反,您应该使用ShortcutManager类中的requestPinShortcut()方法创建应用程序快捷方式。

退房此链接Android 8.0 Behavior Changes