[英]Querying Calendar ICS
I try to read out all existing calendars. 我尝试读出所有现有的日历。 I tried the example from here: 我从这里尝试了示例:
http://developer.android.com/guide/topics/providers/calendar-provider.html 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? 但出现以下编译错误:对于xxx类型,未定义方法getContentResolver()有人可以帮帮我吗?
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 of Context
, so my guess is that your class is not derived from Activity
(which is derived from Context
). getContentResolver()
是Context
一种方法,所以我的猜测是您的类不是从Activity
派生的( Activity
是从Context
派生的)。
You have to use a context variable if you want to call it outside of an activity class ( context.getContentResolver()
). 如果要在活动类( context.getContentResolver()
)之外调用它,则必须使用上下文变量。 If your class is a BroadcastReceiver then the context variable is given as an argument in onReceive()
. 如果您的类是BroadcastReceiver,则上下文变量在onReceive()
作为参数给出。 If not, you have to send it to your method when you call it. 如果不是,则必须在调用它时将其发送到您的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.