2016-06-08 59 views
1

在Android上安裝時,它不會在主屏幕上添加快捷方式,但該應用程序用於。您現在只能在應用程序抽屜中找到它。如何在家庭安卓屏幕上添加應用程序的圖標?如何在家庭安卓屏幕上添加應用圖標(react-native)?

+0

一些黑客可以工作,但沒有在Android上做這個沒有直接的方法....但隨意使用android.intent.action.CREATE_SHORTCUT – Selvin

回答

0
private void removeShortcut() { 
      Intent shortcutIntent = new Intent(getApplicationContext(), 
       MainActivity.class); 
     shortcutIntent.setAction(Intent.ACTION_MAIN); 

     Intent addIntent = new Intent(); 
     addIntent 
       .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
     addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut"); 

     addIntent 
       .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT"); 
     getApplicationContext().sendBroadcast(addIntent); 
    } 
+0

請解釋這個回答有點:)。代碼只有答案大多沒有太大的價值。謝謝你!保持良好的工作! –

+0

我需要添加此代碼的位置? (我不知道java,我正在使用react-native) – Maksim

0
private void addShortcut() { 
    Intent shortcutIntent = new Intent(getApplicationContext(),      MainActivity.class); 
    shortcutIntent.setAction(Intent.ACTION_MAIN); 

    Intent addIntent = new Intent(); 
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut"); 
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 

    Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher); 
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
    getApplicationContext().sendBroadcast(addIntent); 
}