views:

107

answers:

1

Hi

I'm using a similar codesnippet as shown below to add an application shortcut on the homescreen:

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(this, this.getClass().getName());
    shortcutIntent.putExtra(EXTRA_KEY, "ApiDemos Provided This Shortcut");

    // Then, set up the container intent (the response to the caller)

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_name));
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
            this,  R.drawable.app_sample_code);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher

    setResult(RESULT_OK, intent);

There is no problem with creating the shortcut, but when uninstalling the app, the shortcut remains on the homescreen. When uninstalling other apps they all seem to also remove their corresponding homescreen shortcuts. This is what i try to achive with my "created-by-code-shortcut-icon"

Does any of you Android experts here on Stackoverflow know whats needed to remove the app shortcut from the homescreen when the app is uninstalled ?

I found some related threads, but they do not provide me the solution for my problem, but please feel free to catch up:

[0] http://developer.android.com/intl/de/resources/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.html

[1] http://stackoverflow.com/questions/972933/remove-application-from-launcher-programatically-in-android

[2] http://stackoverflow.com/questions/2131690/how-to-remove-application-shortcut-from-home-screen-on-uninstall-automaticaly

A: 

I had the same problem as well.

Finally, i've figured out that when creating application's shortcut, application's intent must contain the Intent.ACTION_MAIN action, otherwise the shortcut won't be removed from the home screen upon uninstalling the application (not the intent being used for installing the shortcut, which has the com.android.launcher.action.INSTALL_SHORTCUT action) .

Hope it helps.

WhiteTigerK