I try to read out all existing calendars. I tried the example from here:
http://developer.android.com/guide/topics/providers/calendar-provider.html
but I get following compile error: The method getContentResolver() is undefined for the type xxx
Can somebody help me please?
public HashMap<String, String> readCalendar() {
String[] EVENT_PROJECTION = new String[] {
Calendars._ID,
Calendars.OWNER_ACCOUNT,
Calendars.ACCOUNT_NAME,
Calendars.CALENDAR_DISPLAY_NAME
};
String selectionICS = "((" + Calendars.ACCOUNT_NAME + " = ?) AND ("
+ Calendars.ACCOUNT_TYPE + " = ?) AND ("
+ Calendars.OWNER_ACCOUNT + " = ?))";
String[] selectionArgs = new String[] {"VISIBLE=1"}; // or "selected=1" ??
Cursor managedCursor = null;
ContentResolver cr = getContentResolver();
managedCursor = cr.query(calendarUri, EVENT_PROJECTION, selectionICS, selectionArgs, null);selectionICS, selectionArgs, null);
}
getContentResolver()is a method ofContext, so my guess is that your class is not derived fromActivity(which is derived fromContext).You have to use a context variable if you want to call it outside of an activity class (
context.getContentResolver()). If your class is a BroadcastReceiver then the context variable is given as an argument inonReceive(). If not, you have to send it to your method when you call it.