I'm allowing the user to create shortcuts using Erel's example here.
The problem I am having is that on some AVDs the shortcut image appears correctly but on others it is way too large. And that took a lot of messing around just to get to that point. I'm trying to do this with my own PNG images (have tried with sizes 72x72 and 96x96) but even using Erel's 48x48 PNG icon does not appear correctly on all AVDs.
I've tried the following using the reflector object but still didn't work:
I've tried the following, but still didn't work:
... and of course in all case, the icon is assigned to tImg then applied to the shortcut like this:
I've tried so many combinations of things and no matter what I do, I can get it to look right on some devices but then it messes it up on others. I've tried LoadBitmap and LoadBitmapSample. I've tried basing things off of the activity "scale" but that didn't help. I thought about basing things off of the apparent density but I know that won't work because of the ones that display correctly, the density is all over the place.
I just don't get what I'm doing wrong. I spent about 8 hours yesterday just messing with these icons, sure that I would figure it out eventually. :BangHead:
My suspicion is that ordinarily when you provide an icon with your app, Android scales it for you, but it seems that when you provide an icon programmatically (as in when passing it to an intent to create a shortcut) then it doesn't do any scaling for you at all. But if this is the case, then I haven't got a clue how to figure out what size it should be. Even if I could, LoadBitmapSample does not return the exact requested size. The routine using the reflection object probably does but it also washes out the colors anyway. But besides that, it didn't solve my problem.
:sign0085:
The problem I am having is that on some AVDs the shortcut image appears correctly but on others it is way too large. And that took a lot of messing around just to get to that point. I'm trying to do this with my own PNG images (have tried with sizes 72x72 and 96x96) but even using Erel's 48x48 PNG icon does not appear correctly on all AVDs.
I've tried the following using the reflector object but still didn't work:
B4X:
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
Dim r As Reflector
Dim b As Bitmap
b = r.RunStaticMethod("android.graphics.Bitmap", "createScaledBitmap", _
Array As Object(Original, Width, Height, Filter), _
Array As String("android.graphics.Bitmap", "java.lang.int", "java.lang.int", "java.lang.boolean"))
Return b
End Sub
I've tried the following, but still didn't work:
B4X:
tbmp = Common.GetAppIcon ' Get's the app's icon to see what size it is
scSize = tbmp.Height
ToastMessageShow (tbmp.Height & "h X " & tbmp.Width & "w", True)
' Works for most but not all ----
tImg.InitializeMutable (scSize, scSize)
tImg = LoadBitmapSample (File.DirAssets, imageFN, scSize, scSize)
... and of course in all case, the icon is assigned to tImg then applied to the shortcut like this:
B4X:
in.PutExtra("android.intent.extra.shortcut.ICON", tImg)
I've tried so many combinations of things and no matter what I do, I can get it to look right on some devices but then it messes it up on others. I've tried LoadBitmap and LoadBitmapSample. I've tried basing things off of the activity "scale" but that didn't help. I thought about basing things off of the apparent density but I know that won't work because of the ones that display correctly, the density is all over the place.
I just don't get what I'm doing wrong. I spent about 8 hours yesterday just messing with these icons, sure that I would figure it out eventually. :BangHead:
My suspicion is that ordinarily when you provide an icon with your app, Android scales it for you, but it seems that when you provide an icon programmatically (as in when passing it to an intent to create a shortcut) then it doesn't do any scaling for you at all. But if this is the case, then I haven't got a clue how to figure out what size it should be. Even if I could, LoadBitmapSample does not return the exact requested size. The routine using the reflection object probably does but it also washes out the colors anyway. But besides that, it didn't solve my problem.
:sign0085: