How to add home screen shortcut without launching app after installation

可紊 提交于 2020-01-15 05:55:18

问题


I am using following code to add shortcut at home screen

private void createShortcut() {
        String appName = getString(R.string.app_name);

        // Adding shortcut for MainActivity
        // on Home screen
        Intent shortcutIntent = new Intent(getApplicationContext(),
                SplashActivity.class);

        shortcutIntent.setAction(Intent.ACTION_MAIN);
        shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY );
        //shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
        addIntent.putExtra("duplicate", false);
        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);

    }

and its manifest permission

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

crateShortcut() code is in my main activity class. When I launch the app shortcut successfully creates at home screen. I want when some one install my app through .apk it automatically create shortcut (without launching the app) on home screen. How I can do this? Is there any broadcast which tells that app installed?? Thanks in advance.


回答1:


In Google play you can set this option to create home shortcut after installation.



来源:https://stackoverflow.com/questions/17102488/how-to-add-home-screen-shortcut-without-launching-app-after-installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!