I have an app that requires periodically checking the date and time server to make sure the date and time are correct. But at the same time, I do not want the user to manually change the date/time in their device settings. I think the best way I could do this is check and see if the "Automatic date & time" option is enabled in settings. Are there any other ways I could do this and what kind of code modules I could use? Please and thanks.
You could periodically take the difference between the time in the server and in the device (mobile/tablet/Pi/etc). With this difference in time you would only need to add it to the time on the device. This way, the user does not need to change the time on the device.
While the examples are great, I would also like it if it used little to no data. Checking the date & time from the server I assume would use some data. That is why I suggested checking to see if that option was enabled in settings would be better.
Sub CheckAutoTime As Boolean
Dim p As Phone
Dim s As String
If p.SdkVersion >= 17 Then s = "android.provider.Settings.Global" Else s = "android.provider.Settings.System"
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim jo As JavaObject
Return jo.InitializeStatic(s).RunMethod("getInt", Array(ctxt.RunMethod("getContentResolver", Null), "auto_time", 0)) = 1
End Sub