Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check "Automatic date and time" is enabled or not?

I need to check whether "Automatic date and time" in the android device is enabled or not. If it is not enabled I need to display the popup that it is not enabled.

Is it possible to achieve. If possible, how to check enabled or not ?

like image 279
sachi Avatar asked Apr 15 '14 05:04

sachi


People also ask

Why is my automatic date and time wrong?

Turn on automatic date and time. Open Settings and then tap General management. Tap Date and time. Tap the switch next to Automatic date and time to turn it back on. Your device will now automatically adjust the time.

Why is my android time wrong?

Turn on Android's automatic date/time setting. Do this through Settings > System > Date & time. Select the button next to Set time automatically to trigger it. If this is already turned on, turn it off, restart your phone, and then turn it back on.


2 Answers

Link for API 17 and above

android.provider.Settings.Global.getInt(getContentResolver(), android.provider.Settings.Global.AUTO_TIME, 0); 

Link for API 16 and below

android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.AUTO_TIME, 0); 
like image 152
velis Avatar answered Oct 14 '22 19:10

velis


public static boolean isTimeAutomatic(Context c) {     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {         return Settings.Global.getInt(c.getContentResolver(), Settings.Global.AUTO_TIME, 0) == 1;     } else {         return android.provider.Settings.System.getInt(c.getContentResolver(), android.provider.Settings.System.AUTO_TIME, 0) == 1;     } } 
like image 27
Hamidreza Sadegh Avatar answered Oct 14 '22 18:10

Hamidreza Sadegh