Android – intent.putextra (intent.extra_shortcut_icon, BMP) image off center
I encountered some problems creating shortcuts on my android desktop
First of all, I have a 72 × 72 icon, I load the bitmap object from the SD card
Using this bitmap object, I set it as my icon resource
The problem I encountered was that when I set it, the image on the shortcut was off center and cut off. I got 72 from the screen indicator × I don't know what the deal is
Code:
Bitmap theBitmap = BitmapFactory.decodeFile("/sdcard/icon.png");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, theBitmap)
I've tried to adjust it and use the canvas to draw and another bitmap to make it work, but when I restart the phone, it reverts to a small size
Use the same icon as a paintable asset to make it look perfect, but it's not dynamic:
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
Use Samsung epic 4G w / 2.1
resolvent:
I have a similar problem. I checked the launcher source code and found that if the initial bitmap size is too small, an error will appear that will cause the icon to not be displayed correctly
First, scale the bitmap to 128 × 128:
Bitmap scaledBitmap = Bitmap.createScaledBitmap(theBitmap, 128, 128, true);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap);
It will solve it