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

identify when user switch between Automatic and manual date & time change

我想确定用户何时切换到 Automatic date & time 因为我试图捕捉 Intent.ACTION_TIME_CHANGED 意图,在 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);