Android System date changed event

Mustansar Saeed picture Mustansar Saeed · May 29, 2014 · Viewed 11.7k times · Source

I know this question has been asked many times but i am unable to find the right direction. I have registered BroadcastReceiver which I want to trigger when the Android System Date is changed automatically but its not firing. I have used the following approaches:

1

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_CHANGED);
registerReceiver(new DateTimeChangeReceiver (), intentFilter);

2-> AndroidManifest.xml

<receiver android:name=".DateTimeChangeReceiver ">
<intent_filter>
    <action android:name="android.intent.action.DATE_CHANGED"/>
</intent_filter>
</receiver>

DateTimeChangeReceiver

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class DateTimeChangeReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Toast.makeText(context, "Date changed", Toast.LENGTH_SHORT).show();
    }

}

In both cases, reciever is not being triggered. It only shows the notification when manually time is being set. Can anyone please point me out what I am missing?

Thanks in advance.

Answer

Ramki Anba picture Ramki Anba · May 29, 2014

There are broadcasts for those events. ACTION_TIME_CHANGED and ACTION_DATE_CHANGED ACTION docs at http://developer.android.com/reference/android/content/Intent.html#ACTION_DATE_CHANGED

A potential bug and some implementation details available at http://code.google.com/p/android/issues/detail?id=2880