Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android M shortcut install/uninstall duplication

I am trying to create a shortcut for my application through a service. The following code is working on SDK <= 21, but its not working correctly on SDK = 23

The creation of the shortcut is done this way:

        Intent shortcutIntent = new Intent(this, MainActivity.class);
        shortcutIntent.putExtra(EXTRA_SHORTCUT_CLICKED, true); //This is only to check when the user clicked on the created shortcut
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

        Intent addIntent = new Intent();
        addIntent.putExtra("duplicate", false);
        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TEST");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.application_icon));
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

        sendBroadcast(addIntent);

In SDK <= 21 the shortcut is created and if already exists it will not create other instance.

In SDK = 23 the shortcut will only be duplicated if I press the created shorcut and try to create the shortcut again, or If I reboot the device and then try to create the shortcut again.

I tried to uninstall the shortcut first but without success on SDK 23, as follows:

        Intent shortcutIntent = new Intent(this, MainActivity.class);
        shortcutIntent.putExtra(EXTRA_SHORTCUT_CLICKED, true); //This is only to check when the user clicked on the created shortcut
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

        Intent addIntent = new Intent();
        addIntent.putExtra("duplicate", false);
        addIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "TEST");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.application_icon));
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

        sendBroadcast(addIntent);

This is the service implementation:

public class MyService extends Service {

 @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        createShortcut(); //This is where I create the shortcut
        return super.onStartCommand(intent,flags,startId);
    }
}

Did Android 6 changed the shortcut creation politics? I cannot find anything on the documentation.

[UPDATE] I tried to make this shortcut creation by clicking on a button on a sample application and this still happens. The shorcut will duplicate once I click on the created shortcut and then try to create it again. Same thing happens rebooting the device.

[UPDATE2] I was looking on the grep code for the Launcher3 google application and I found that the shortcut installation calls the registerSessionCallback which depends on the calling thread. Might be an issue regarding these new changes?

like image 320
iGoDa Avatar asked Mar 15 '23 12:03

iGoDa


1 Answers

For people who got stuck with the same issue:

Google removed support of Uninstall shortcut on Launcher3 and Google now Launcher on Android M.

Additionally, the duplication of shortcuts is an issue on the lastest Android M build (MRA58K) and its now on the development team hands.

You guys can follow the issue here, https://code.google.com/p/android/issues/detail?id=179697

[UPDATE] Google has just fixed the issue and it will be released on the next version.

like image 177
iGoDa Avatar answered Mar 25 '23 03:03

iGoDa