This question is indeed a duplicate to Listen for new calendar events
I have been trying to register the BroadcastReceiver with the way specified in the link, however, my app couldn't receive any broadcast when I modified the phone's calendar.
I also tried to add it through IntentFilter instead of through the AndroidManifest
filter = new IntentFilter();
filter.addAction(Intent.ACTION_PROVIDER_CHANGED);
registerReceiver(calendarReceiver,filter);
still no luck getting it to receive the broadcast. Did I miss anything or listening to calendar's changes cannot be done anymore?
You must add the scheme and and authority for calendar events:
filter.addDataScheme("content");
filter.addDataAuthority("com.android.calendar", null);
A complete example of listening for calendar changes would be:
CalendarReceiver.java
public class CalendarReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("example", "Calendar changed (or the phone just booted)");
}
}
Activity.java
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PROVIDER_CHANGED);
filter.addDataScheme("content");
filter.addDataAuthority("com.android.calendar", null);
registerReceiver(new CalendarReceiver(), filter);