user3782779
user3782779

Reputation: 1689

Force Android to update actual device time

I am developing and app that need to access to actual device hour frequently. I can detect if device hour is correct or wrong comparing with server time, if device hour is wrong I need to change automatically to real hour.

I've seen that to change the time of device programmatically is necessary to have rooted device.

Is there any way to force synchronization of the time when you know it's not right that does not require root?

If not possible. Is there any way that my app has a internal clock different to clock of the device (in sync with my server), to not call the server every time I want the time and to get the correct time when even I have no Internet?

Upvotes: 0

Views: 3259

Answers (1)

alijandro
alijandro

Reputation: 12147

  1. For the third-party app, there is no way to set system time without root permission.

  2. Yes, you could use Calender and the following intents broadcast from system to build a internal clock. Another way to simplify the work is using TextClock widget directly as an internal clock and use reflect mechanism to set and track the time of TextClock if you don't want to build your own clock. As long as your app keep running, the internal clock will work.

    Intent.ACTION_TIME_CHANGED
    Intent.ACTION_TIME_TICK
    Intent.ACTION_TIMEZONE_CHANGED
    

Upvotes: 2

Related Questions