Date and Time automatica

Asked

Viewed 532 times

2

I’m developing an application on Android and would like to know if anyone knows of an application with open source or knows the code that checks if the automatic date and time option (provided by the network) is enabled on the device.

thank you

  • You are using which version of the API?

2 answers

1

I use the 18, but the tip is already, I found these codes

API 17 to top

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

API 16 down

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

1

To do this, use the property AUTO_TIME .

Here is an example of implementation:

   int type =0;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
           type =  Settings.Global.getInt(getContentResolver(), Settings.Global.AUTO_TIME, 0);
        }else{
           type =  Settings.System.getInt(getContentResolver(), Settings.System.AUTO_TIME, 0);
        }

If your return is 1, then the option is enabled! Otherwise it returns 0.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.