Android Question Add App to Home Screen

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I am looking for the possibility to add my App to the Home Screen.

I found:
B4X:
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

But this adds a shortcut. It is different when I copy my App from the App Screen by holding the Icon and move it to the home screen.
To remove the App from the device, I can do this by holding the Icon and move it to delete the app.
Doying so on a shortcut, it only removes the shortcut.

Can somebody how to copy/add my App to the home screen?

Kind regards,
André
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…