How to Place App Icon on Launcher Home Screen

Drop a launcher icon on Android home screen (like Google Play does)

I don't think the solution with the use of getDrawableForDensity is the most correct. You should let the launcher decide, passing the resource name as you can see in this example:

private void createAppShortcut(String packageName) {

PackageManager packageManager = getPackageManager();

ApplicationInfo appInfo = null;
Resources resources = null;

try {
appInfo = packageManager.getApplicationInfo(packageName, 0);
resources = packageManager.getResourcesForApplication(packageName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return;
}

Intent shortcutIntent = packageManager.getLaunchIntentForPackage(packageName);
CharSequence shortcutName = appInfo.loadLabel(packageManager);

Intent.ShortcutIconResource shortcutIconResource = new Intent.ShortcutIconResource();
shortcutIconResource.packageName = packageName;
shortcutIconResource.resourceName = resources.getResourceName(appInfo.icon);

Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
shortcut.putExtra("duplicate", false);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIconResource);
sendBroadcast(shortcut);
}

Android Home Screen App Icon With Unwanted Mini-Icon Badge

Does anyone know how to prevent this badge from being displayed?

Generally speaking, that's not an option. The standard OS-supplied rendering of a pinned shortcut includes what you refer to as the badge, and there is no means of opting out of that badge. Presumably, that is to help avoid apps from masquerading as other apps via these shortcuts.

Note another app's icon above mine has a mini badge that is not the same as it's main icon

I assume that you refer to "Patio Motion...". The larger icon is the icon for the shortcut. The smaller icon ("badge") in the lower right is the icon for the app (i.e., what shows up in Settings and elsewhere).

In your case, you appear to have set the shortcut icon to be the same as your launcher icon, which is why you have this duplicate effect. Use a different icon for the shortcut, ideally one that represents the action being taken by that shortcut.

As it stands, it seems like your shortcut is simply to launch your app, which is not what shortcuts are for. Most users can put a launcher icon on their home screen without the need for your app to publish a shortcut.

How do you change the launcher logo of an app in Android Studio?

Look in the application's AndroidManifest.xml file for the <application> tag.

This application tag has an android:icon attribute, which is usually @drawable/ic_launcher.
The value here is the name of the launcher icon file. If the value is @drawable/ic_launcher, then the name of the icon is ic_launcher.png.

Find this icon in your resource folders (res/mipmap-mdpi, res/mipmap-hdpi, etc.) and replace it.

A note on mipmap resources: If your launcher icon is currently in drawable folders such as res/drawable-hdpi, you should move them to the mipmap equivalents (e.g. res/mipmap-hdpi). Android will better preserve the resolution of drawables in the mipmap folder for display in launcher applications.

Android Studio note: If you are using Android Studio you can let studio place the drawables in the correct place for you. Simply right click on your application module and click New -> Image Asset.

For the icon type select either "Launcher Icons (Legacy Only)" for flat PNG files or "Launcher Icons (Adaptive and Legacy)" if you also want to generate an adaptive icon for API 26+ devices.



Related Topics



Leave a reply



Submit