2

I have a requirement to update the current time in my application as per device time format(12/24). I need any callback/listeners/receivers which will let me know that time format has been changed so that i can update time in my application accordingly.

I got the way to get current timeformat using below code snippet

String value = android.provider.Settings.System.getString(this.getContentResolver(), android.provider.Settings.System.TIME_12_24);

But looking for any callback which will let me know the same in run time.

Thanks in advance.

Daud Arfin
  • 2,499
  • 1
  • 18
  • 37

1 Answers1

0

android.text.format.DateFormat.is24HourFormat(Context context); Use this function to get the time format. Register a Broadcast receiver which listens to ACTION_TIMEZONE_CHANGED,ACTION_TIME_CHANGED,ACTION_TIME_TICK.

Something like this,

IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_TICK);
intentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
intentFilter.addAction(Intent.ACTION_TIME_CHANGED);
registerReceiver(youReciverHere,intentFilter);

Do work on the receiver s onReceive() function.

Sree Vishnu
  • 385
  • 2
  • 13