1

In my android application I want the app to use date and time provided by the network. User should not be able to use manual time mode. Whenever user switches to manual mode time zone app should throw a message similar to whatsapp "user phone date is inaccurate" and prevent the user from using the app further. Any complete example?

Andrej Istomin
  • 2,527
  • 2
  • 15
  • 22
Abm
  • 271
  • 2
  • 15
  • You just call the API. check from the API. – Ticherhaz FreePalestine Jan 18 '23 at 06:14
  • @Ticherhaz FreePalestine - Is it possible on app side? – Abm Jan 18 '23 at 06:18
  • 1
    If you want to ensure ```Automatic date & time``` is always switched on, you may take a look in this previous post: https://stackoverflow.com/questions/23075446/how-to-check-automatic-date-and-time-is-enabled-or-not – Enowneb Jan 18 '23 at 06:19
  • Related: [How can I get the "network" time, (from the "Automatic" setting called "Use network-provided values"), NOT the time on the phone?](https://stackoverflow.com/questions/8049912/how-can-i-get-the-network-time-from-the-automatic-setting-called-use-netw) Search for more. – Ole V.V. Jan 18 '23 at 06:24
  • @Enowneb I implemented code from the link you gave but it is checking only when the activity is loaded. So user can maniplulate the time ..Is there a way where it can be checked continuously if automatic time zone is selected? – Abm Jan 18 '23 at 09:05
  • 1
    Are you implementing the checking in ```onCreate()```? Is there any chance to do that in ```onResume()``` if the ```Activity``` is not destroyed? – Enowneb Jan 18 '23 at 09:57
  • @Enowneb - yes was using in onCreate() – Abm Jan 18 '23 at 11:02
  • 2
    @Abm Try to move your checking into ```onResume()```. After user has left the ```Activity```, go to ```Setting```, switch off ```Automatic date & time```, and return back to the ```Activity```, ```onResume()``` is called. Therefore you can put your checking there to guarantee it will run every time when the ```Activity``` is on screen. – Enowneb Jan 18 '23 at 12:34
  • 2
    @Enowneb - onResume() is working – Abm Jan 18 '23 at 13:12

0 Answers0