Android Question [SOLVED] Set phone clock from GPS

Discussion in 'Android Questions' started by Claudio Parmigiani, Apr 6, 2015.

  1. Claudio Parmigiani

    Claudio Parmigiani Member Licensed User

    Hi all,
    is there some way to adjust the phone system clock using GPS data ?

    I am already using GPS data in my APP for location purposes and it works fine.
    The problem is that phone's clock cannot be syncronized via NTP (no data plan is used) and it slows down for several minutes each day.

    The "Automatic Adjust" via Mobile Network work only once, at reboot.

    The solution I look for should also work with non-rooted phones, if possible.
    Any hint ?

    Thank you for the support, as usual....
    :)

    Regards,
    Claudio.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is not possible to programmatically set the device date / time.
     
  3. Claudio Parmigiani

    Claudio Parmigiani Member Licensed User

    Hi Erel,
    thanks for your feedback.

    Actually, I might have found a way to do what I need in rooted phones (without installing 3rd party software).

    Using the library 'b4arootcmd' it is possible to execute the command 'date' as root and therefore adjust the time/date.
    Here follows a little example:

    Code:
    Sub GPS_LocationChanged (Location1 As Location)
        
    '
        'do your stuff here
        '
        '
        Dim rc As RootCmd
        
    Dim NewTime=Location1.Time As String
        NewTime=(NewTime.substring2(
    0,10))
        rc.execRootCmd(
    "date "&NewTime)
        
    '
    End Sub

    Of course the APP will have to be authorized to execute root commands by the SuperSU APP.

    The solution above could be useful in case of non-continuous position tracking (I.E. Start GPS > Get Position > Stop GPS > wait for some time > Start GPS ....) otherwise the time/date will be set at every position change.

    I am thinking about setting a counter to fire the date command every 'x' location changes...

    Thanks for your support,
    Regards,
    Claudio.
     
    Troberg likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice