Android Question [SOLVED] Set phone clock from GPS

Claudio Parmigiani

Member
Licensed User
Longtime 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.
 

Claudio Parmigiani

Member
Licensed User
Longtime 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:

B4X:
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.
 
Upvote 0
Top