Android Question Using user-selectable images for shortcuts

Kevin

Well-Known Member
Licensed User
Longtime User
I am revisiting an old problem. A while back I was having problems with shortcut images not scaling correctly on all devices. They would show only a partial image as the icon... squashed, or too large and off-centered, etc.

I finally resolved this with help from Erel by retrieving drawables that I included with the app. See this thread.

Anyway, I am still having a problem, but it is when I allow the user to choose their own image from their SD card. It results in the same problem I initially had. They do not scale correctly. It seems that unless the image is a "drawable", it simply does not scale correctly when applied as a shortcut image.

Has anyone ever had this problem and solved it? Is there a way I can convert an image loaded from the SD card into a "drawable" through code? No matter what size the icon (png) is on my SD card (72x72, 96x96, 144x144, etc), it never renders correctly as a shortcut icon. It only works properly if loaded as a drawable resource from my app.

See also:
http://stackoverflow.com/questions/...t-extra-shortcut-icon-bmp-image-is-off-center

I tried using the method shown in the last post on Stack Overflow (basically getting the size that Android is using for the app's icon and scaling the loaded bitmap) but it still doesn't work properly.
 

LucaMs

Expert
Licensed User
Longtime User
Have you tried to use the suggestion in the page that you've linked (stackoverflow)?

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
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Yes, I did. I was so certain I had found the solution that I leaned back and smiled as I waited for my app to compile. Unfortunately my smile faded after I tried it with the same result as before.

I'm not sure what I am doing wrong or why it isn't working. Have you (or anyone else) had success with this? I'm running out of ideas.
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Unfortunately it didn't help. Strange (and frustrating) problem! Such a simple idea to use an icon off of the SD card for a shortcut and the only simple thing is that it simply doesn't work. I don't know why none of the solutions seem to fix the problem.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…