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

Discussion in 'Android Questions' started by Vitt61, Jun 29, 2015.

  1. Vitt61

    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!
     
  2. eurojam

    eurojam Well-Known Member Licensed User

    Vitt61 likes this.
  3. Vitt61

    Vitt61 Member Licensed User

  4. DonManfred

    DonManfred Expert Licensed User

    No, that´s java.
    You need to write a wrapper-library for this to be used in B4A or maybe you can use the lib Root-CMD to call the shell commands posted on your link
     
    Vitt61 likes this.
  5. Vitt61

    Vitt61 Member Licensed User

    Thank you, I try it!
     
  6. rtek1000

    rtek1000 Member Licensed User

    Tested (KitKat)

    Code:
    shell_cmd("date -s " & IntToStr4(date_year) & _
                                    IntToStr2(date_month) & _
                                    IntToStr2(date_day) & 
    "." & _
                                     IntToStr2(time_hour) & _
                                     IntToStr2(time_min) & 
    "00")
    Code:
    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
    Code:
    Sub shell_cmd(Command_in As StringAs 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
     
    Ferbis and Ed Brown like this.
Loading...