查询日历ICS

时间:2012-06-16 17:13:59

标签: android calendar

我尝试读出所有现有的日历。我从这里尝试了这个例子:

http://developer.android.com/guide/topics/providers/calendar-provider.html

但我得到以下编译错误:方法getContentResolver()未定义类型xxx 有人可以帮帮我吗?

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);


}

1 个答案:

答案 0 :(得分:1)

getContentResolver()Context的一种方法,因此我的猜测是您的课程不是来自Activity(来自Context)。

如果要在活动类(context.getContentResolver())之外调用它,则必须使用上下文变量。如果您的类是BroadcastReceiver,那么上下文变量将作为onReceive()中的参数给出。如果没有,您必须在调用时将其发送到您的方法。

相关问题