25

I have googled, but I can find no advice to prevent user change system date/time in android.

We are developing an Enterprise Application, we would like to prevent the user of the device to be able to set time settings. In other words, we want to set a policy which defines, that user cant change date and time in android device. Are there any recommendations to do this? Thanks.

jimp
  • 16,999
  • 3
  • 27
  • 36
Faisal Silitonga
  • 423
  • 1
  • 7
  • 14
  • I'm sure its not possible. You can use broadcast receiver to be informed when time has been changed by user and after that base on your calculation do whatever you want. I think its not good experience for your users when they see they cannot change time because of your application. – Hesam Oct 17 '12 at 02:19
  • I doubt it would be possible. The first priority of a phone is to get calls and SMS right, second priority would be basic things like time and date. An app shouldn't be able to block any of those functions. – Muz Oct 17 '12 at 02:27
  • 2
    You guys are missing the point: this is an enterprise app. Which means that having an exact time is important: you may need to know _exactly_ when emails have been sent, or verify certificates which depends on time. Priorities depend on usage. – Nikolay Elenkov Oct 17 '12 at 03:04

4 Answers4

5

Here is a third alternative that should significantly save on battery life:

Register a BroadCast Receiver for when the time gets changed by the user. Then disable the app until the device time is checked against network-time or server-time.

Those Broadcast Receivers exist. I just checked now with this app called Internal Broadcast Monitor I just found on Google Play.

enter image description here

Here is the interesting part below where I changed both the time and the date:

enter image description here

And below is the part where I changed the time zone: enter image description here.

Stephan Branczyk
  • 9,363
  • 2
  • 33
  • 49
  • This not works if user close app service and then he change device time. – user3782779 Jun 08 '16 at 14:56
  • @user3782779, A Broadcast Receiver does not require a service to be running. That's the entire point. – Stephan Branczyk Jun 08 '16 at 17:56
  • Then, can I run a piece of my code in Broadcast Receiver even in my process and my service is killed? – user3782779 Jun 08 '16 at 19:24
  • Inside of a Broadcast Receiver, yes, but only if it's a quick action that will return immediately. The common pattern is to create a Service or an Activity and have that launched by the Broadcast Receiver when the Broadcast Receiver is triggered. And yes, in effect that's the recommended way of doing things instead of having a long term service. Either use a Broadcast Receiver or the AlarmManager to launch/relaunch your service as needed instead of having a long term Service. – Stephan Branczyk Jun 08 '16 at 22:27
3

Since there is no policy support for this in the device administrator framework, you can't. File a feature request, it might get added in a next version.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • Thanks i found i can prevent user change date/time setting by prevent user access date/time setting activity in android. – Faisal Silitonga Nov 05 '12 at 07:54
  • And how did you manage this? Whatever you have, it is highly unlikely that it will work reliably on all Android version, especially recent ones. – Nikolay Elenkov Nov 05 '12 at 08:59
  • 1
    I using the activity manager to check what activity that running. So i can call another activity if user choose date/time setting activity. – Faisal Silitonga Nov 12 '12 at 01:51
1

I don't know of any way that you can change the default behavior of the device.
You can however prevent your application from running if the system time differs from the network time. Or you could use the network time in your app instead of system time.

The answer to this post explains how to access the network time.

How can I get the "network" time, (from the "Automatic" setting called "Use network-provided values"), NOT the time on the phone?

Community
  • 1
  • 1
Jason Hessley
  • 1,608
  • 10
  • 8
1

you can save current time to db when application start and check every 1 minutes if current time not equal to db time+60 set system time to db time+60.

Ehsan Jelodar
  • 1,544
  • 19
  • 25