I need to have a function that returns a boolean if a time on a device is set by user or it is a default network time. Searching the internet gave me no results. Please, share some knowledge on me
CodePudding user response:
You can try this way and to find out more go to this link
try {
if(Settings.Global.getInt(getContentResolver(), Settings.Global.AUTO_TIME) == 1)
{
// Auto Enabled
}
else
{
// Disabed
}
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
CodePudding user response:
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;
}
}