Is it possible to prevent the Google Play app from

2020-08-13 01:43发布

问题:

When you install an app via Google Play, a shortcut for the app is created on your home screen. The user can prevent this from happening by disabling the "Auto-add Widget" setting within the Google Play app.

From a developer standpoint, I'm wondering if it's possible to prevent this from within my own app. Is there a manifest setting or something else that tells Google not to create an icon for my app on install?

Having no Launcher Activity is not an option for my app.

回答1:

http://viralpatel.net/blogs/android-install-uninstall-shortcut-example/ this tutorial is very useful for adding or removing shortcut on homepage

Uninstall Shortcut from Home screen Similar to install, uninstalling or removing shortcut in Android uses an Intent (UNINSTALL_SHORTCUT) to perform the task. In following code we remove the shortcut added on home screen.

Again we need a permission to perform uninstall shortcut task. Add following permission to Android manifest xml.

private void removeShortcut() {

        //Deleting shortcut for MainActivity 
        //on Home screen
        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);
    }