Sub RequestPinShortcut (id As String, ShortLabel As Object, Update As Boolean)
Dim ctxt As JavaObject
Dim icon As Bitmap
icon.Initialize(File.DirAssets,"Icon.png")
ctxt.InitializeContext
Dim ShortcutManagerCompat As JavaObject
ShortcutManagerCompat.InitializeStatic("androidx.core.content.pm.ShortcutManagerCompat")
Dim supported As Boolean = ShortcutManagerCompat.RunMethod("isRequestPinShortcutSupported", Array(ctxt))
If supported Then
Dim builder As JavaObject
builder.InitializeNewInstance("androidx.core.content.pm.ShortcutInfoCompat.Builder", Array(ctxt, id))
builder.RunMethod("setShortLabel", Array(ShortLabel))
builder.RunMethod("setIcon", Array(CreateIconFromBitmap(icon)))
Dim in As Intent
in.Initialize(in.ACTION_MAIN, "")
in.SetComponent(Application.PackageName & "/.main") 'lower case
builder.RunMethod("setIntent", Array(in))
Dim info As JavaObject = builder.RunMethod("build", Null)
If Update Then
Dim infos As List = Array(info)
Log("Update successfully? " & ShortcutManagerCompat.RunMethod("updateShortcuts", Array(ctxt, infos)))
Else
ShortcutManagerCompat.RunMethod("requestPinShortcut", Array(ctxt, info, Null))
End If
End If
End Sub
Private Sub CreateIconFromBitmap(bmp As Bitmap) As Object
Dim ic As JavaObject
Return ic.InitializeStatic("androidx.core.graphics.drawable.IconCompat").RunMethod("createWithBitmap", Array(bmp))
End Sub