Android Question how to set automatic widget android in home screen

mehdibm69

New Member
hi my app is have a widget for make my app live for get and send gps location services i want after run my app if widget is no active in home screen is automaticly added this in there
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This should let the user add widget:
B4X:
Private Sub Button1_Click
    Dim ComponentName As JavaObject
    ComponentName.InitializeNewInstance("android.content.ComponentName", Array(Application.PackageName, "widgetreceiver"))
    Log(ComponentName)
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim AppWidgetManager As JavaObject
    AppWidgetManager = AppWidgetManager.InitializeStatic("android.appwidget.AppWidgetManager").RunMethod("getInstance", Array(ctxt))
    Log(AppWidgetManager.RunMethod("isRequestPinAppWidgetSupported", Null))
    Log(AppWidgetManager.RunMethod("requestPinAppWidget", Array(ComponentName, Null, Null)))
End Sub

However it doesn't seem to work...
 
Upvote 0
Top