在android中以编程方式启用“使用网络提供的值”

时间:2013-09-10 07:33:56

标签: android eclipse

我希望能够在提示用户之后以编程方式检查此选项

这样的东西
if (android.systemtime==false)
 {
  systemtime=true;
  }
这可能吗?任何帮助将不胜感激

1 个答案:

答案 0 :(得分:5)

您正在寻找Settings.System.AUTO_TIME次设置(已在API级别17中移至Settings.Global.AUTO_TIME)。在引入API级别17之前,您可以读取并更改该值,但现在此值对于非系统应用程序是只读的。

private boolean isAutoTimeEnabled() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // For JB+
        return Settings.Global.getInt(getContentResolver(), Settings.Global.AUTO_TIME, 0) > 0;
    }
    // For older Android versions
    return Settings.System.getInt(getContentResolver(), Settings.System.AUTO_TIME, 0) > 0;
}