2017-10-20 95 views
2

我正在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

是,面臨同樣的問題:( –

回答

0

作爲Android開發者

的com.android.launcher.action.INSTALL_SHORTCUT廣播不再對您的應用程序沒有任何影響,因爲它現在是一個私人的,隱含的廣播提及。相反,您應該使用ShortcutManager類中的requestPinShortcut()方法創建應用程序快捷方式。

退房此鏈接Android 8.0 Behavior Changes

相關問題