Android Question screen widget in Android version 12

Kadandale Ganapathy Bhat

Member
Licensed User
Dear all
I followed the widget tutorial and very much successful upto android 11
But now in Android 12 it does not shown and refreshed.
please help

widget:
#Region Module Attributes

    #StartAtBoot: False

#End Region



Sub Process_Globals

    Dim showw As String

    Dim rv1 As RemoteViews

    Dim extrarefreshtimer As Timer

    Dim voiceindex As Int

    Dim calitem As String

    Dim rv1 As RemoteViews

    Dim PHONE As Phone

    Dim apalarmtime As String

    Dim currentImage As Int

    Dim curreenttext As Int

    Dim refreshtimer As Timer

    Dim nextdate As String

    Dim nexttime As String

    Dim apointupdatewidet As String

    Dim txtlist As List

    Dim txtpanch As String

    Dim txtlistenglish As List

    Dim langstatus As String

    Dim dayindex As Int

    Dim thithilist() As String

    Dim finalpanchangaenglish As String

    Dim thithilne As String

    Dim dayindex1 As String

    Dim widtext As String

    Dim widtexthead As String

    Dim widtextnew As String

    Dim thitxt As List

    Dim naktxt As List

    Dim fileno As Int

    Dim path1 As String

    Dim thiaudiolist As List

    Dim txtlistenglish As List

    Dim alarmplay As String

    Dim stopcross As String

End Sub

Sub Service_Create

    rv1 = ConfigureHomeWidget("L1", "rv", 10, "English Panchanga 2021")

End Sub



Sub Service_Start (StartingIntent As Intent)

    If File.Exists(File.DirInternal,"widget.txt") = False Then

        Main.widgetshow = "lazy"

        Main.widgetnew =  "lazy"

    End If

  

    If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then



        File.WriteString(File.DirInternal,"widget.txt","DELETED")

        Main.widgetshow = "deleted"

        Log("deleted")

        showw = "deleted"

    else If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DISABLED" Then

        File.WriteString(File.DirInternal,"widget.txt","DISABLED")

        'CallSubDelayed(Main,"nowidg

        Main.widgetshow = "DISABELED"

        Log("disabled")

        showw = "DISABELED"

    else If StartingIntent.Action = "android.appwidget.action.APPWIDGET_ENABLED" Then

        File.WriteString(File.DirInternal,"widget.txt","ENABLED")

        'CallSubDelayed(Main,"nowidg

        Main.widgetshow = "ENABLED"

        Log("enabled")

        showw = "ENABLED"



    End If

    rv1_RequestUpdate

  



    If StartingIntent.Action = "android.appwidget.action.APPWIDGET_ENAABLED" Then

        Log("enabled")

    End If

    If StartingIntent.Action = "android.appwidget.action.APPWIDGET_DELETED" Then

  

        Log("disbled")

        Main.widgetstatus = "no"

        Log(Main.widgetstatus)



        Return

    End If

  



    If rv1.HandleWidgetEvents(StartingIntent) = False Then

        rv1_RequestUpdate

    End If

    If StartingIntent.Action <> "android.appwidget.action.APPWIDGET_DISABLED" Then

        StartServiceAt("", TimeToNextMinute, False)

    End If

End Sub



Sub rv1_RequestUpdate

    refreshtimer_tick

    Main.widgetstatus = "yes"

    DateTime.DateFormat = "HH:mm:SS"

    rv1.SetText("lClock", DateTime.Time(DateTime.Now))

    rv1.UpdateWidget



If File.Exists(File.DirInternal,"newuser1.txt") = True Then

    refreshtimer_tick

    Main.widgetstatus = "yes"

    DateTime.DateFormat = "HH:mm:SS"

    rv1.SetText("lClock", DateTime.Time(DateTime.Now))

    rv1.UpdateWidget

End If

    If showw = "ENABLED" Then

        File.WriteString(File.DirInternal,"widget.txt","ENABLED")

        Main.widgetshow = "ENABLED"

        Log("working")



    else if showw = "DISABLED" Then

        File.WriteString(File.DirInternal,"widget.txt","DISABLED")

        Main.widgetshow = "DISABELED"

        Log("Disabled")



    else if showw = "DELETLED" Then

        File.WriteString(File.DirInternal,"widget.txt","DELETED")

        Main.widgetshow = "deleted"

        Log("Dileted")

    End If

End Sub



Sub rv1_Disabled

    CancelScheduledService("")

    StopService("")

End Sub



Sub Service_Destroy



End Sub



Sub TimeToNextMinute As Long

    Dim ret As Long



    ret = DateTime.Now + DateTime.TicksPerMinute

    ret = ret - (ret Mod DateTime.TicksPerMinute)

    Return ret

End Sub

Sub refreshtimer_tick

    If stopcross = "finish" Then

        rv1.SetVisible("Imageview2",False)

        rv1.SetVisible("Imageview1",True)

        stopcross = ""

    End If

    If Main.check = "one" Then

        Main.check = ""

        Main.check1 = ""

        rv1.SetVisible("Imageview2",False)

        rv1.SetVisible("Imageview1",True)



    Else



    End If

    SetTime

    Dim language As String

    If File.Exists(File.DirInternal,"lang.txt") = False Then

        File.WriteString(File.DirInternal,"lang.txt","ed")

    End If

    langstatus = File.ReadString(File.DirInternal,"lang.txt")

    loadlist

    seltoday

    If Main.daywiddetail = "" Then

        Dim language As String

        If File.Exists(File.DirInternal,"lang.txt") = False Then

            File.WriteString(File.DirInternal,"lang.txt","ed")

        End If

        langstatus = File.ReadString(File.DirInternal,"lang.txt")

        loadlist

        seltoday

    Else

        langstatus = File.ReadString(File.DirInternal,"lang.txt")

        loadlist

        seltoday



    End If

    rv1.SetText("Label2",widtext)

    If langstatus = "tu" Then

        If File.Exists(File.DirInternal,"01.jpg") = True Then

            rv1.SetVisible("imageful",True)

            rv1.SetImage("imageful",LoadBitmap(File.DirInternal,"01.jpg"))

        End If

    Else

        rv1.SetVisible("imageful",False)



    End If

    Dim altime As String = PHONE.GetSettings(("next_alarm_formatted"))

    If altime <> "" Then

        rv1.SetVisible("mobalarm",True)

    Else

        rv1.SetVisible("ImageView4",False)

        rv1.SetVisible("ImageView6",False)

        rv1.SetVisible("mobalarm",False)



    End If

    rv1.SetText("Label2",widtext) ' Alarm

    If File.Exists(File.DirInternal,"alartm.txt") = False Then

        File.WriteString(File.DirInternal,"alartm.txt","on&06:00")

    End If



    apalarmtime = File.ReadString(File.DirInternal,"alartm.txt")

    If apalarmtime.Contains("on") Then

        rv1.SetVisible("apalarm",True)

        rv1.SetText("apalarm","Alarm in App" & CRLF & apalarmtime.Replace("on&",""))

    Else

        rv1.SetVisible("apalarm",False)

    End If

    rv1.SetText("Label2",widtext)

    refreshappointment

    rv1.UpdateWidget

End Sub

Sub imageful_click

    StartActivity(dailyshow)

End Sub

Sub seltoday

    If File.Exists(File.DirInternal,"vsst1.vss") = False Then

        File.Copy(File.DirAssets,"vsst1.vss",File.DirInternal,"vsst1.vss")

        File.Copy(File.DirAssets,"vsst2.vss",File.DirInternal,"vsst2.vss")

        File.Copy(File.DirAssets,"vsst3.vss",File.DirInternal,"vsst3.vss")

        File.Copy(File.DirAssets,"vsst4.vss",File.DirInternal,"vsst4.vss")

        File.Copy(File.DirAssets,"vsst5.vss",File.DirInternal,"vsst5.vss")

        File.Copy(File.DirAssets,"vsst6.vss",File.DirInternal,"vsst6.vss")

        File.Copy(File.DirAssets,"vssn1.vss",File.DirInternal,"vssn1.vss")

        File.Copy(File.DirAssets,"vssn2.vss",File.DirInternal,"vssn2.vss")

        File.Copy(File.DirAssets,"vssn3.vss",File.DirInternal,"vssn3.vss")

        File.Copy(File.DirAssets,"vssn4.vss",File.DirInternal,"vssn4.vss")

        File.Copy(File.DirAssets,"vssn5.vss",File.DirInternal,"vssn5.vss")

        File.Copy(File.DirAssets,"vssn6.vss",File.DirInternal,"vssn6.vss")

        File.Copy(File.DirAssets,"vssn7.vss",File.DirInternal,"vssn7.vss")

        File.Copy(File.DirAssets,"vsss1.vss",File.DirInternal,"vsss1.vss")

        If File.Exists(File.DirInternal,"setting.txt") = False Then

            File.WriteString(File.DirInternal,"setting.txt","20" & CRLF & "Colors.Blue" & CRLF & "Colors.RGB(255,250,218)")

        End If

        File.Copy(File.DirAssets,"vss61.vss",File.DirInternal,"vss61.vss")

        File.Copy(File.DirAssets,"vss6.vss",File.DirInternal,"vss6.vss")

        File.Copy(File.DirAssets,"vss7.vss",File.DirInternal,"vss7.vss")

        File.Copy(File.DirAssets,"vss8.vss",File.DirInternal,"vss8.vss")

        File.Copy(File.DirAssets,"vss9.vss",File.DirInternal,"vss9.vss")

        File.Copy(File.DirAssets,"vss10.vss",File.DirInternal,"vss10.vss")

        File.Copy(File.DirAssets,"vss11.vss",File.DirInternal,"vss11.vss")

        File.Copy(File.DirAssets,"vss11.vss",File.DirInternal,"vss11.vss")

    End If

    txtlistenglish = File.Readlist(File.DirAssets,"vss61.vss")

    If langstatus = "kt" Or langstatus = "et" Or langstatus = "tt" Then

        txtlistenglish = File.Readlist(File.DirAssets,"vss61t.vss")

    End If

    If langstatus = "ed" Or langstatus = "et" Then

        thitxt = File.Readlist(File.DirAssets,"vsst1.vss")

        naktxt = File.Readlist(File.DirAssets,"vssn1.vss")

    Else If langstatus = "sa" Then

        thitxt = File.Readlist(File.DirAssets,"vsst2.vss")

        naktxt = File.Readlist(File.DirAssets,"vssn2.vss")

    Else If langstatus = "kd" Or langstatus = "kt" Then

        thitxt = File.Readlist(File.DirAssets,"vsst3.vss")

        naktxt = File.Readlist(File.DirAssets,"vssn3.vss")

    Else If langstatus = "te" Then

        thitxt = File.Readlist(File.DirAssets,"vsst4.vss")

        naktxt = File.Readlist(File.DirAssets,"vssn4.vss")

    Else If langstatus = "ta" Then

        thitxt = File.Readlist(File.DirAssets,"vsst5.vss")

        naktxt = File.Readlist(File.DirAssets,"vssn5.vss")

    Else If langstatus = "ma" Then

        thitxt = File.Readlist(File.DirAssets,"vsst6.vss")

        naktxt = File.Readlist(File.DirAssets,"vssn6.vss")

    Else If langstatus = "tu" Or langstatus = "tt" Then

        thitxt = File.Readlist(File.DirAssets,"vsst7.vss")

        naktxt = File.Readlist(File.DirAssets,"vssn7.vss")

    End If

    DateTime.DateFormat = "dd-MMM"

    Dim todaydate As String

    Dim todayyear As String

    Dim datepos As Int

    Dim finalpanchanga As String

    Dim dayitem As String

    todaydate = DateTime.Date(DateTime.Now)

    DateTime.DateFormat = "yyyy"

    todayyear = DateTime.Date(DateTime.Now)

    DateTime.DateFormat = "dd-MMM"

    'lbmsec1.Text = "Today's Panchanga" & CRLF & todaydate & " " & todayyear





    For i = 0 To txtlist.Size-1

        dayitem = txtlist.Get(i)

        If dayitem.Contains(todaydate) And dayitem.Contains(todayyear) Then

            finalpanchanga = dayitem

            dayindex = i

'            Log(dayindex)

        End If

    Next

    Dim presentday As String = todaydate & "-" & todayyear

    For i = 0 To txtlistenglish.Size-1

        dayitem = txtlistenglish.Get(i)

        'If dayitem.Contains(todaydate) Then

        If dayitem.Contains(presentday) Then

            finalpanchangaenglish = dayitem

            dayindex1 = i

'            Log(dayindex)

          

        End If

    Next

    calitem = finalpanchanga.Substring2(7,finalpanchanga.Length-5)& CRLF & " " & CRLF

  

    Dim typepanch As String

    If langstatus = "kd" Then

        typepanch= " - ದೃಗ್ಗಣಿತ"

    Else If langstatus = "kt" Then

        typepanch= " - ತಿಥಿನಿರ್ಣಯ"

    Else If langstatus = "sa" Then

        typepanch= " - दृग्गणितम्"

    Else If langstatus = "td" Then

        typepanch= " - Drigganitha"

    Else If langstatus = "tt" Then

        typepanch= " - Thithinirnaya"

    Else If langstatus = "te" Then

        typepanch= " - దృగ్గణిత"

    Else If langstatus = "ta" Then

        typepanch= " - த்ருக்கணித"

    Else If langstatus = "ma" Then

        typepanch= " - ദൃഗ്ഗണിത"

    Else If langstatus = "ed" Then

        typepanch= " - Drigganitha"

    Else If langstatus = "et" Then

        typepanch= " - Thithinirnaya"

    End If

    widtext = "Today's Panchanga" & typepanch &  CRLF & todaydate & " " & todayyear & CRLF &  calitem

    widtexthead = "Today's Panchanga" & CRLF & todaydate & " " & todayyear

    widtextnew = calitem



End Sub

Sub loadlist

    txtlistenglish = File.ReadList(File.DirAssets,"vss61.vss")

    thithilne = File.ReadString(File.DirAssets,"vss61.vss")

  

    If langstatus = "ed" Then

        txtlist = File.Readlist(File.DirAssets,"vss6.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss6.vss")

  

    Else If langstatus = "et" Then

        txtlist = File.Readlist(File.DirAssets,"vss6t.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss6t.vss")

  

        txtlistenglish = File.ReadList(File.DirAssets,"vss61t.vss")

        thithilne = File.ReadString(File.DirAssets,"vss61t.vss")

    Else If langstatus = "sa" Then

        txtlist = File.Readlist(File.DirAssets,"vss7.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss7.vss")

  

    Else If langstatus = "tu" Then

        txtlist = File.Readlist(File.DirAssets,"vss11.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss11.vss")



    Else If langstatus = "tt" Then

        txtlist = File.Readlist(File.DirAssets,"vss11t.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss11t.vss")

  

        txtlistenglish = File.ReadList(File.DirAssets,"vss61t.vss")

        thithilne = File.ReadString(File.DirAssets,"vss61t.vss")

    Else If langstatus = "kd" Then

        txtlist = File.Readlist(File.DirAssets,"vss8.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss8.vss")

  

    Else If langstatus = "kt" Then

        txtlist = File.Readlist(File.DirAssets,"vss8t.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss8t.vss")



        txtlistenglish = File.ReadList(File.DirAssets,"vss61t.vss")

        thithilne = File.ReadString(File.DirAssets,"vss61t.vss")

    Else If langstatus = "te" Then

        txtlist = File.Readlist(File.DirAssets,"vss9.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss9.vss")



    Else If langstatus = "ta" Then

        txtlist = File.Readlist(File.DirAssets,"vss10.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss10.vss")



    Else If langstatus = "ma" Then

        txtlist = File.Readlist(File.DirAssets,"vss11.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss11.vss")



    Else If langstatus = "tu" Then

        txtlist = File.Readlist(File.DirAssets,"vss11.vss")

        txtpanch = File.ReadString(File.DirAssets,"vss11.vss")

    End If

End Sub

Sub seltoyear

    DateTime.DateFormat = "dd-MMM-yyyy"

    Dim todaydate As String

    Dim datepos As Int

    Dim finalpanchanga As String

    Dim dayitem As String

    todaydate = DateTime.Date(DateTime.Now)

  

End Sub

Sub refreshappointment

    DateTime.DateFormat = "yyyy-MMM-dd"

    Dim apointlist As List

    Dim singleapoint As String

    Dim nextapoint As Long

    nextapoint = 0

    Dim nowtick As Long = DateTime.DateTimeParse(DateTime.Date(DateTime.Now),DateTime.Time (DateTime.Now))

  

    If File.Exists(File.DirInternal,"vss.vss") = True Then

        apointlist = File.Readlist(File.Dirinternal,"vss.vss")

    Else

        apointlist.Initialize

    End If

    For i = 0 To apointlist.Size-1

        singleapoint = apointlist.Get(i)

        singleapoint = singleapoint.SubString2(0,13)

        If singleapoint> nowtick Then

            If nextapoint = 0 Then

                nextapoint = singleapoint

            End If

        End If

    Next



    Dim h, m As Int

    h = Floor((nextapoint - DateTime.Now) / DateTime.TicksPerHour)

    m = ((nextapoint - DateTime.Now) - h * DateTime.TicksPerHour) / DateTime.TicksPerMinute

    If nextapoint > 0 Then

        DateTime.DateFormat = "dd-MMM-yyyy"

        rv1.SetText("mobalarm","Schedule at - " & DateTime.Date(nextapoint) & " " & DateTime.Time(nextapoint))

        nextdate = DateTime.Date(nextapoint)

        nexttime = DateTime.Time(nextapoint)

    Else

        DateTime.DateFormat = "dd-MMM-yyyy"

        rv1.SetText("mobalarm","Schedule at - (Click here to set!")

        nextdate = DateTime.Date(DateTime.Now)

        nexttime = DateTime.Time(DateTime.Now)

    End If



End Sub

Sub SetTime

    rv1.SetText("Label3", DateTime.Time(DateTime.Now))

End Sub

Sub ImageView1_Click

    Main.voicestatus1 = ""

    Main.check1 = ""

  

    rv1.SetVisible("ImageView1",False)

    rv1.SetVisible("ImageView2",True)

    seltoday

    audiolist

    rv1.SetText("Label2",Main.daywiddetail)

    rv1.UpdateWidget

    StartActivity(screen3)

  

End Sub

Sub ImageView2_Click

    Log("clicked")

    starter.MP.Stop

    Main.check1 = "one"

    rv1.SetVisible("ImageView2",False)

    rv1.SetVisible("ImageView1",True)

End Sub

Sub lblaudio_Click



    seltoday

    audiolist

    rv1.SetText("Label2",Main.daywiddetail)

    rv1.UpdateWidget

End Sub

Sub Label2_Click

    StartActivity(Main)

End Sub

Sub apalarm_Click

    If starter.MP.IsPlaying = True Then

        starter.MP.Stop

        starter.timeralarm.Enabled = False

        starter.alarmplay = ""

    Else

        StartActivity(Main)

    End If

End Sub

Sub audiolist

    alarmplay = ""

    DateTime.DateFormat = "dd-MMM-yyyy"

    path1 = File.DirAssets

    thiaudiolist.Initialize

    thiaudiolist.Clear

    Log(finalpanchangaenglish)

    thithilist = Regex.Split(",",finalpanchangaenglish.SubString2(12,finalpanchangaenglish.Length))

    For i = 0  To thithilist.Length-1

        thiaudiolist.Add(thithilist(i)& ".mp3")

    Next

'    Log(thiaudiolist)

    Main.thiaudiolist = thiaudiolist

    Main.fileno = 0

    Main.voiceindex = 0

    Main.voiceindex = Main.fileno + 1

    starter.MP.Load(File.DirAssets,thiaudiolist.Get(fileno))

    starter.MP.Play

  

End Sub

Sub mobalarm_click



    apointupdatewidet = "yes"

    Log(apointupdatewidet)

    Log(nextdate)

    If nextdate <> "" Then



        StartActivity(appoint)

    End If



End Sub



Sub refreshapoint1

  

End Sub
 
Last edited:

AnandGupta

Expert
Licensed User
Longtime User
But now in Android 12 it does not shown and refreshed.
Your code is too long to read and understand.
Better try below sample, thanks to @Sagenut

I use it and it works perfect in Android 12
 
Upvote 0
Top