我想确定用户何时切换到 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/