【问题标题】:How to add icon of the app on the home android screen (react-native)?如何在主android屏幕上添加应用程序的图标(react-native)?
【发布时间】:2016-06-08 08:42:13
【问题描述】:

在Android上安装时,它不会在主屏幕上添加快捷方式,而是在应用程序上添加。您现在只能在应用程序抽屉中找到它。如何在安卓主屏幕上添加应用图标?

【问题讨论】:

  • 一些 hacks 可能会奏效,但在 android 上没有直接的方法可以做到这一点......但请随意使用 android.intent.action.CREATE_SHORTCUT

标签: javascript android react-native apk


【解决方案1】:
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);
    }

【讨论】:

  • 请稍微解释一下这个答案:)。仅代码的答案大多没有多大价值。感谢你!继续努力!
  • 我需要在哪里添加此代码? (我不懂java,我正在使用react-native)
【解决方案2】:
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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 2019-02-10
    • 1970-01-01
    • 2012-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    相关资源
    最近更新 更多