I would like to be able to turn the automatic date time settings on and off from tasker. I don't see a way to do this directly but I can use tasker to issue a shell command. I know I can just use the date command to change the date to some specific date but is there a way to turn the automatic setting off and on from a command line or tasker?
2 Answers
It might be useful to check the android source to find the exact package name to the system settings, specifically this source responsible for date/time, line 226 is the key!
Have played with tasker before, but can tasker directly modify system properties? as in directly do this, I am quoting line 228 the pertinent part:
Settings.Global.putInt(
getContentResolver(),
Settings.Global.AUTO_TIME_ZONE,
autoZoneEnabled ? 1 : 0);
In short the actual direct name to the package would be com.android.settings/.DateTimeSettings
, if that's of any help!
By using adb shell
's Android Activity Manager, am
, one can start the activity to go directly into that screen as in am start -n com.android.settings/.DateTimeSettings
, experiment and see if that fits your needs as I have not actually played with it. :)
-
There is also a
Settings.Global.AUTO_TIME
settings that you can also disable for auto date & time. Commented Sep 5, 2017 at 14:45 -
The setting wasn't working for me on Android10/Q but this method worked: stackoverflow.com/a/68055904/573377 DevicePolicyManager dpm = (DevicePolicyManager) getApplicationContext().getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName component = new ComponentName(getApplicationContext(), DeviceAdminReceiver.class); dpm.setGlobalSetting(component, Settings.Global.AUTO_TIME, enable ? "1" : "0");– jeoffmanCommented Aug 4, 2021 at 18:41
turn on:
settings put global auto_time 1
turn off:
settings put global auto_time 0
source: Android sourcecode
-
1An example using ADB would be:
$ adb shell settings put global auto_time 1
Commented Mar 31, 2021 at 23:48