android - 识别用户何时在自动和手动日期和时间更改之间切换

标签 android android-date

我想确定用户何时切换到 Automatic date & time为此,我试图捕获 Intent.ACTION_TIME_CHANGED intent ,在 Automatic date & time 的情况下触发两次.但是当我们手动更改时间时 Intent.ACTION_TIME_CHANGED只触发一次。

我曾尝试使用 autoTimeCalled 静态变量来识别,现在我想识别用户何时手动更改了日期。

public static boolean isAutoTimeCalled= false

if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED)){

    autoTimeCalled++;
    if( autoTimeCalled ==2 ){

        Log.e("AUTO" , autoTimeCalled+"");                  
        autoTimeCalled =0;
        isAutoTimeCalled = true;

    }       
}

谁能建议我更好的方法来区分手动和自动时间操作。

最佳答案

在你的接收器中获取值:

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

它会告诉您当前的设置。适用于 API 17 及更高版本。

对于较低的 API

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

关于android - 识别用户何时在自动和手动日期和时间更改之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29508205/

相关文章:

java - 尝试启动新 Activity 时出现空指针异常

android - 如何显示成功 Toast 消息

android - 如何在android顶部的 ListView 中添加新项目

java - 在Java/Android中获取年、月、日和时间形式 "Tue, 12 Jan 2016 09:40:07 GMT"

android - 如何处理服务器和 native android 应用程序之间的时区差异?

java - 如何将月份缩写为 3 个字符?

android - 使用 Google API 客户端库和自行访问 token 端点有什么区别

java - 如何删除标题 View ?或者修复这个异常: "Cannot add header view to list - setAdapter has already been called"

Android如何将这种格式(/Date(1418346257000+0700)/)转换为Date对象