Widget Help: Updating a label text from html every 5 mins

wck01

New Member
Licensed User
Longtime User
Hi All,

I want to develop a widget to update a label text from a given web site every 5 mins. I know how to load a html source from a standard program (not widget), see below code. However, I don't know how to put it in widget. Does anybody give me some advice?

Regards,
Kit

B4X:
'Activity module
Sub Process_Globals
   Dim PhoneIntents1 As PhoneIntents
  Dim MainUrl As String
End Sub

Sub Globals
   Dim ListView1 As ListView
   Dim WebView1 As WebView
   Dim Label1 As Label
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
  activity.LoadLayout("form1")

   HttpUtils.CallbackActivity = "Main"
   HttpUtils.CallbackJobDoneSub = "JobDone"

   MainUrl = "http://news.google.com.hk/news?edchanged=1&ned=us"
   
   HttpUtils.Download("Main page", MainUrl)   

End Sub 

Sub Activity_Resume

End Sub

Sub JobDone(Job As String)
   Select job
      Case "Main page"
         Load_Details
   End Select
End Sub

Sub Load_Details
  Dim TextReader1 As TextReader
  TextReader1.Initialize2(HttpUtils.GetInputStream(MainUrl),"utf8")
  line = TextReader1.ReadAll

  TextReader1.Close
   Label1.Text = line
End Sub
 

wck01

New Member
Licensed User
Longtime User
Hi Erel,

Actually, I tried the widget tutorial and modified the codes. I can compile the code and install to my android phone. However, when I add to the widget to my home screen. A force close message box appear.

I attached my project files. What was wrong with my codes?
 

Attachments

  • Test.zip
    23.9 KB · Views: 299
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should check the logs and find the error message. It will probably appear in the unfiltered logs.
SS-2011-12-04_11.48.07.png
 
Upvote 0

wck01

New Member
Licensed User
Longtime User
Hi Erel,

Thanks for pointing out the great tool to check. I found the issue although I don't know how to solve it. There are some issues to call HttpUtils module under widget.

Finally, I use http library to replace. Now, my widget works. It's excellent.

Much appreciated.

Kit
 
Upvote 0
Top