After adding code that populates the device's home screen with a shortcut icon for my app, the icon appears as an aliased icon, with the main icon I'm trying to install on the home page and a mini version of the icon that's some sort of badge at the lower-right corner of my icon. Does anyone know how to prevent this badge from being displayed?
The EyeSee icon is the one for my app. Note another app's icon above mine has a mini badge that is not the same as it's main icon. I'd love to know how to create this alternate badge icon, but I'd be most grateful just to get rid of the mini alias icon - for now.
Here's my code for creating the shortcut when OnCreate runs for the main activity.
private void createOrUpdateShortcut()
{
SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);
if(!isAppInstalled)
{
Context appContext = getApplicationContext();
Intent homeScreenShortCut= new Intent(appContext, MainActivity.class);
homeScreenShortCut.setAction(Intent.ACTION_MAIN);
homeScreenShortCut.putExtra("duplicate", false);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
{
homeScreenShortCut.setPackage(appContext.getPackageName());
homeScreenShortCut.setClass(appContext, MainActivity.class);
homeScreenShortCut.setClassName(appContext.getPackageName(), String.valueOf(MainActivity.class));
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
assert shortcutManager != null;
if (shortcutManager.isRequestPinShortcutSupported())
{
ShortcutInfo pinShortcutInfo =
new ShortcutInfo.Builder(this, "browser-shortcut-")
.setShortLabel(appContext.getResources().getString(R.string.app_name))
.setLongLabel(appContext.getResources().getString(R.string.app_name))
.setIcon(Icon.createWithResource(this,R.drawable.ic_launcher))
.setIntent(homeScreenShortCut)
.build();
shortcutManager.requestPinShortcut(pinShortcutInfo, null);
System.out.println("added_to_homescreen");
} else {
System.out.println("failed_to_add");
}
} else {
if(shortcutReinstall)
{
Intent removeIntent = new Intent();
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, homeScreenShortCut);
String prevAppName = appPreferences.getString("appName", getString(R.string.app_name));
removeIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, prevAppName);
removeIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(removeIntent);
}
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, homeScreenShortCut);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
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);
}
//Make preference true
SharedPreferences.Editor editor = appPreferences.edit();
editor.putBoolean("isAppInstalled", true);
editor.putString("phoneLanguage", currentLanguage);
editor.putString("appName", getString(R.string.app_name));
editor.commit();
}
}
