我试着读出所有现有的日历。我试过这里的例子:
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);
}
最佳答案
getContentResolver()
是 Context
的一个方法,所以我猜你的类不是派生自 Activity
(派生自上下文
).
如果您想在 Activity 类之外调用它,则必须使用上下文变量 (context.getContentResolver()
)。如果您的类是 BroadcastReceiver,则上下文变量作为参数在 onReceive()
中给出。如果没有,您必须在调用它时将其发送到您的方法。
关于android - 查询日历 ICS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11065492/