0

I have published an app “Sensor Recording” in the Google Play Store. It is available in two variants: “Lite” (free of charge) and “Pro” (full functionality). Software internally, they are distinguished by different flavors and each of them has a unique icon with the related text on it. After download and installation, the related shortcut icon (=launcher icon?) is placed on the home screen.

Lite Variant Pro Variant

So far, the two variants can be downloaded separately in the Play Store. Now, I want to integrate an Upgrade feature with In-app billing, so that a user of the Lite version can easily change to the higher level, if desired. The logic behind that is ready, tested and works perfectly (but is not yet uploaded into to Play Store). The actual variant and version can be seen in the headline of the app.

Headline Lite

Headline Pro

So far so good. However, the launcher icon remains the same. Of course, I want to replace it programmatically after the successful Upgrade.

I’m aware that the mechanism for that has been changed by Google with Android O (API level 26), requesting user interaction for some operations. Thus, ancient threads from years ago don’t work anymore, e.g. How to change an application icon programmatically in Android? According to Google's documentation https://developer.android.com/guide/topics/ui/shortcuts/creating-shortcuts#java, I tried the following code:

// preparation
Context appContext = context.getApplicationContext();
Class   myClass    = context.getClass();
String  appName    = context.getString(R.string.app_name);

// try to replace the icon
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)   // Android 8.0 "Oreo" (SDK 26)
{
    Intent intent = new Intent(appContext, myClass);
    intent.setAction(Intent.ACTION_MAIN);

    ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat
        .Builder(context,"dynamic-shortcut")
        .setShortLabel(appName)
        .setIcon(IconCompat.createWithResource(context, R.drawable.iconpro))  // <== the new icon to replace the existing one
        .setIntent(intent)
        .build();

    ShortcutManagerCompat.pushDynamicShortcut(context, shortcutInfo);
}

But nothing happens – no user interaction, no update of the launcher icon. What am I doing wrong?

0 Answers0