The most commonly suggested solution is to use Settings.Global.putInt(getContentResolver(), Settings.Global.AUTO_TIME, 1)
. You will end up seeing this message in logcat, though:
Setting auto_time has moved from android.provider.Settings.System to android.provider.Settings.Global, value is unchanged.
According to the Android documentation, apps cannot modify these settings.
https://developer.android.com/reference/android/provider/Settings.Global
Global system settings, containing preferences that always apply identically to all defined users. Applications can read these but are not allowed to write; like the "Secure" settings, these are for preferences that the user must explicitly modify through the system UI or specialized APIs for those values.
These settings are read-only unless your app is installed as a system app or is signed by the manufacturer of the device that it is running on.
Most people end up rooting their device but there is an alternative. Device Owner apps can modify global system settings through a different API.
https://developer.android.com/reference/android/app/admin/DevicePolicyManager#setGlobalSetting(android.content.ComponentName,%20java.lang.String,%20java.lang.String)
You would do it like so:
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");
This alternative is mostly suitable for homebrew apps and proprietary Android-based products because the device cannot have user accounts. Play Store will not install apps as Device Owner, it must be done manually.
Here is how to do it with ADB:
https://developer.android.com/work/dpc/dedicated-devices/cookbook#dev-setup