0

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?

Community
  • 1
  • 1
user3782779
  • 1,669
  • 3
  • 22
  • 36
  • 1
    The last question you posed seems easy. Just grab the server time, calculate the difference to your local time. Save that difference, and then you know all you have to do is add the difference to local time when you display – Cruncher Apr 09 '15 at 15:04
  • I also need real hour even if the user willfully change the device hour after sync with server. – user3782779 Apr 09 '15 at 15:11
  • If you don't have connection to the server, and the user changes the time on you, there's not much you can do if your app isn't running constantly. Do you mind sharing why you want to do this? It may help us come up with better alternatives. – Cruncher Apr 09 '15 at 15:34

1 Answers1

2
  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
    
alijandro
  • 11,627
  • 2
  • 58
  • 74