Listen to android calendar changes. (Sync/Delete/Insert etc..)

后端 未结 1 663
天命终不由人
天命终不由人 2020-12-29 11:23

I\'ve understand I have to use Content Provider to get all changes, but I also realized starting API14 there is a ready Content Provider

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 11:39

    First you need to add this type of receiver to the Manifest:

        
            
                
                
                
            
        
    

    Then create a simple class which extends broadcast receiver:

    public class CatchChangesReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
        // add processing here with some query to content provider
            // in my project I use this selection for getting events:
             final String SELECTION = CalendarContract.Events.CALENDAR_ID + "="
                + calendarId + " AND " + "("
                + CalendarContract.Events.DIRTY + "=" + 1 + " OR "
                + CalendarContract.Events.DELETED + "=" + 1 + ")" + " AND "
                + CalendarContract.Events.DTEND + " > "
                + Calendar.getInstance().getTimeInMillis();
        }
    }
    

    0 讨论(0)
提交回复
热议问题