Android Question How can to set the date and time the Android system?

Vitt61

Member
Licensed User
HI,
I have the Date and Time from RTC and I like to use this data for set the Date and Time in the Android System (Tablet), HOW? The standard DateTime function are only ready ...
Thank you for help to me!
 

rtek1000

Active Member
Licensed User
Tested (KitKat)

B4X:
    shell_cmd("date -s " & IntToStr4(date_year) & _
                                IntToStr2(date_month) & _
                                IntToStr2(date_day) & "." & _
                                 IntToStr2(time_hour) & _
                                 IntToStr2(time_min) & "00")
B4X:
Sub IntToStr2(val1 As Int) As String
    Dim str1 As String
   
    str1 = ""
   
    If val1 < 10 Then
        str1 = str1 & "0"
    End If
   
    str1 = str1 & val1
   
    Return str1
End Sub

Sub IntToStr4(val1 As Int) As String
    Dim str1 As String
   
    str1 = ""
   
    If val1 < 1000 Then
        str1 = str1 & "0"
    End If
    If val1 < 100 Then
        str1 = str1 & "0"
    End If
    If val1 < 10 Then
        str1 = str1 & "0"
    End If
   
    str1 = str1 & val1
   
    Return str1
End Sub
B4X:
Sub shell_cmd(Command_in As String) As String
    Dim Result As Int
    Runner = File.Combine(File.DirInternalCache, "runner")
    Command = File.Combine(File.DirInternalCache, "command")

    File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
    File.WriteString(File.DirInternalCache, "command", Command_in & CRLF & "exit") 
    'Any commands via crlf, and exit at end
    StdOut.Initialize
    StdErr.Initialize

    Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)

    'Msgbox(StdOut.tostring, "")
    Return StdOut.tostring
End Sub
 
Top