2

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

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


}
4

1 回答 1

1

getContentResolver()是 的一种方法Context,所以我的猜测是您的类不是派生自Activity(派生自Context)。

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

于 2012-06-16T17:39:32.423 回答