Android Tutorial Android home screen widgets tutorial - part II

Status
Not open for further replies.

fotosettore

Member
Licensed User
Longtime User
hi erel
is there a way to understand if a widget is present on any page of smathphone ?
many thanks
 

corwin42

Expert
Licensed User
Longtime User
hi erel
is there a way to understand if a widget is present on any page of smathphone ?
many thanks

In my (advanced) tutorial about different widget instances I have a Sub that returns all Widget Ids of widgets which are present on any homescreen.

B4X:
'Get the Ids of all instances of this widget on the homescreen created by the given service
'
' ServiceName - The name of the WidgetService
Public Sub GetWidgetIds(ServiceName As String) As Int()
    Dim Obj1, Obj2 As Reflector
    Dim cn As Object
   
    Obj2.Target = Obj1.RunStaticMethod("android.appwidget.AppWidgetManager", "getInstance", Array As Object(Obj1.GetContext), Array As String("android.content.Context"))
    cn = Obj1.CreateObject2("android.content.ComponentName", Array As Object(Obj1.GetContext, Obj1.GetStaticField("anywheresoftware.b4a.BA", "packageName") & "." & ServiceName & "$" & ServiceName & "_BR"), Array As String("android.content.Context", "java.lang.String"))
    Return Obj2.RunMethod4( "getAppWidgetIds", Array As Object(cn), Array As String("android.content.ComponentName"))
End Sub

The sub returns an array of Ids. So if the number of Ids is bigger than 0 at least one widget is active on a homescreen.
The sub needs the name of your widget service in lowercase as a parameter.
 

chrjak

Active Member
Licensed User
Longtime User
Hey Erel,

Is it possible to add a miniature picture for the Widgets? For example on my Phone with Android 4.4 you can see at the Widgets Part the Design already. There is only the app logo yet.
 

Wembly

Member
Licensed User
Longtime User
Hi All

Can anyone please advise if its possible to configure a widget to take the full width of the screen. Using a width of 294 as recommend leaves quite a gap to the right side of the widget.

Thanks
 

zlatan

Member
Licensed User
Longtime User
Hi everybody,
how can I make the widget to get updated each time an internet connection is detected?
I need it particularly in case when the phone resumes from sleep mode or when it accesses a wifi network.
Thanks
 

chrjak

Active Member
Licensed User
Longtime User
You can try to check at _updatewidget if there is a internet connection...

Regards
 

zlatan

Member
Licensed User
Longtime User
You can try to check at _updatewidget if there is a internet connection...

Regards

Thanks,
but my question was: how to invoke the UpdateWidget method whenever an internet connection becomes available.
 

chrjak

Active Member
Licensed User
Longtime User
You can make a service checking the connection. and then you can call the rvupdate manually
 

zlatan

Member
Licensed User
Longtime User
You can make a service checking the connection. and then you can call the rvupdate manually

Yes, it makes sense. I was just wondering if there is some easier way to do this.
Thanks for the tip.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…