Image of aim.putExtra (Intent.EXTRA_SHORTCUT_ICON, bmp) is out of center

I'm having a slight problem when creating shortcuts on the Android desktop.

Firstly, I have a 72x72 icon, I load it from an SD card into a Bitmap object.

With this raster object, I set it as an icon resource.

The problem I am facing is when I install it, the image on the shortcut is displayed in the center and turned off. From the screen metrics, I get a size of 72x72, not sure what the deal is.

the code:

Bitmap theBitmap = BitmapFactory.decodeFile("/sdcard/icon.png");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, theBitmap)

I tried to resize it and make it work using canvas, a picture, and another bitmap, however when I restart the phone it returns to a small size.

Using the same icon as a resource with the ability to draw makes it ideal, but not dynamic:

Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

Samsung Epic 4g w/2.1

+3
2

. Launcher, , , - , .

128x128:

Bitmap scaledBitmap = Bitmap.createScaledBitmap(theBitmap, 128, 128, true);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap);

.

+7

-, :

int size = (int) getResources().getDimension(android.R.dimen.app_icon_size);
installer.putExtra(Intent.EXTRA_SHORTCUT_ICON, Bitmap.createScaledBitmap(b, size, size, false));
+5

Source: https://habr.com/ru/post/1787893/


All Articles