Hi All,
My app, with a calendar widget was developed and tested with my device, running Android 4.4. Recently update to Android 5. cause the widget fail to load its content. USB debug shows below code error when I try to add a widget to homescreen:
Here is the code of my widget:
And here is list of lib I use:
BroadCastReceiver
Core
DateUtils
Gestures
IME
JavaObject
Phone
Reflection
SQL
May anyone help me please. Thank you.
My app, with a calendar widget was developed and tested with my device, running Android 4.4. Recently update to Android 5. cause the widget fail to load its content. USB debug shows below code error when I try to add a widget to homescreen:
** Service (widget2x2s) Create **
** Service (widget2x2s) Start **
0
0
0
getTasks: caller 10252 does not hold GET_TASKS; limiting output
Here is the code of my widget:
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public rv As RemoteViews
End Sub
Sub Service_Create
rv = ConfigureHomeWidget("widget2x2", "rv", 1440, "E-Calendar(Solar)")
End Sub
Sub Service_Start (StartingIntent As Intent)
' If a widget is removed from homescreen we don't need to do anything
If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then Return
' We have to be sure that we do not start the service
' again if all widgets are removed from homescreen
If StartingIntent.Action <> "android.appwidget.action.APPWIDGET_DISABLED" Then
Dim schedule As Long
Dim now As Long = DateTime.now
schedule = DateUtils.SetDateAndTime(DateTime.GetYear(now), DateTime.GetMonth(now), DateTime.GetDayOfMonth(now),0,1,0)
If schedule < now Then
'skip to tomorrow
Dim p As Period
p.Days = 1
schedule = DateUtils.AddPeriod(schedule, p)
End If
StartServiceAt("",schedule,True)
End If
' Handle the widget events
If rv.HandleWidgetEvents(StartingIntent) = False Then
' If the action is not handled by HandleWidgetEvents() then we
' probably were called by StartService() or StartServiceAt().
' So just update the widget.
rv_RequestUpdate
End If
If IsPaused(screen_orientation) = True Then
'Log("not running")
StartService(screen_orientation)
End If
End Sub
Sub rv_RequestUpdate
rv.SetTextSize("Loading", 20)
DateTime.DateFormat = "dd.MM.yyyy"
Dim header As String = DateTime.date(DateTime.now)
Dim day As Int= DateTime.GetDayOfWeek(DateTime.now)
If day = 1 Then header = "Sun, " & header
If day = 2 Then header = "Mon, " & header
If day = 3 Then header = "Tue, " & header
If day = 4 Then header = "Wed, " & header
If day = 5 Then header = "Thu, " & header
If day = 6 Then header = "Fri, " & header
If day = 7 Then header = "Sat, " & header
rv.SetImage("Bg",CommonCode.DrawFont("","Bg",0,0,False))
rv.SetImage("Header",CommonCode.DrawFont(header,"Header",0,0,False))
rv.SetImage("SL",LoadBitmapSample(File.DirAssets,"solar.png",20dip,20dip))
rv.SetImage("Line",CommonCode.DrawFont("","Line",0,0,False))
rv.UpdateWidget
Dim first As String = "01." & DateTime.GetMonth(DateTime.Now) & "." & DateTime.GetYear(DateTime.Now)
Dim first_day As Int = DateTime.GetDayOfWeek(DateTime.DateParse(first))
first_day = first_day-2
If first_day < 0 Then first_day = 6
Dim no_of_days_in_mth As Int = DateUtils.NumberOfDaysInMonth(DateTime.GetMonth(DateTime.Now),DateTime.GetYear(DateTime.Now))
Dim lb_no As Int
Dim target_lb As String
Dim date_str As String
Dim pre_month As Int = DateTime.GetMonth(DateTime.Now) - 1
Dim pre_year As Int = DateTime.GetYear(DateTime.Now)
If pre_month = 0 Then
pre_month = 12
pre_year = pre_year - 1
End If
Dim prefix As Int = DateUtils.NumberOfDaysInMonth(pre_month,pre_year)
prefix = prefix - first_day +1
If first_day > 0 Then
For i = 0 To first_day-1
lb_no = i + 1
target_lb = "ImageView" & lb_no
rv.SetImage(target_lb,CommonCode.DrawFont(prefix,"Date_S",i,0,False))
prefix = prefix+1
Next
End If
rv.UpdateWidget
Dim date As Int = 1
Dim suffix As Int = 1
For j = 0 To 5
For i = 0 To 6
lb_no = i + j*7 + 1
target_lb = "ImageView" & lb_no
If j = 0 Then
If i >= first_day Then
DateTime.DateFormat = "ddMMyyyy"
If DateTime.GetMonth(DateTime.Now) < 10 Then date_str = date & "0" & DateTime.GetMonth(DateTime.Now) & DateTime.GetYear(DateTime.Now)
If DateTime.GetMonth(DateTime.Now) >= 10 Then date_str = date & DateTime.GetMonth(DateTime.Now) & DateTime.GetYear(DateTime.Now)
If date <10 Then date_str = "0" & date_str
If DateTime.DateParse(date_str) - DateTime.DateParse(DateTime.date(DateTime.now)) <> 0 Then rv.SetImage(target_lb,CommonCode.DrawFont(date,"Date",i,j,False))
If DateTime.DateParse(date_str) - DateTime.DateParse(DateTime.date(DateTime.now)) = 0 Then rv.SetImage(target_lb,CommonCode.DrawFont(date,"Date",i,j,True))
date = date+1
End If
End If
If j > 0 Then
If date > no_of_days_in_mth Then
rv.SetImage(target_lb,CommonCode.DrawFont(suffix,"Date_S",i,j,False))
suffix = suffix+1
End If
If date <= no_of_days_in_mth Then
DateTime.DateFormat = "ddMMyyyy"
If DateTime.GetMonth(DateTime.Now) < 10 Then date_str = date & "0" & DateTime.GetMonth(DateTime.Now) & DateTime.GetYear(DateTime.Now)
If DateTime.GetMonth(DateTime.Now) >= 10 Then date_str = date & DateTime.GetMonth(DateTime.Now) & DateTime.GetYear(DateTime.Now)
If date <10 Then date_str = "0" & date_str
If DateTime.DateParse(date_str) - DateTime.DateParse(DateTime.date(DateTime.now)) <> 0 Then rv.SetImage(target_lb,CommonCode.DrawFont(date,"Date",i,j,False))
If DateTime.DateParse(date_str) - DateTime.DateParse(DateTime.date(DateTime.now)) = 0 Then rv.SetImage(target_lb,CommonCode.DrawFont(date,"Date",i,j,True))
date = date+1
End If
End If
Next
rv.UpdateWidget
Next
rv.SetVisible("Line",True)
rv.SetVisible("LineS",True)
rv.SetVisible("Loading",False)
rv.UpdateWidget
StopService("")
End Sub
Sub rv_Disabled
StopService("")
CancelScheduledService("")
End Sub
Sub Service_Destroy
End Sub
Sub Button1_Click
StartActivity(Main)
End Sub
And here is list of lib I use:
BroadCastReceiver
Core
DateUtils
Gestures
IME
JavaObject
Phone
Reflection
SQL
May anyone help me please. Thank you.