Search code examples
androidandroid-date

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


I want to identify when user has switched to Automatic date & time for that i have tried to catch Intent.ACTION_TIME_CHANGED intent , which fires twice in case of Automatic date & time. But when we change time manually Intent.ACTION_TIME_CHANGED fires only once.

i have tried to identify by using autoTimeCalled static variable and now i want to identify when user has changed date manually.

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;

    }       
}

can anyone suggest me the better approach to bifurcate between manual and auto time operations.


Solution

  • Fetch value in your receiver:

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

    It will tell you current settings. It is for API 17 and above.

    For lower API

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