如何查询用户的日历?

时间:2018-08-01 06:55:33

标签: android database android-calendar

public static final String[] EVENT_PROJECTION = new String[] {
        CalendarContract.Calendars._ID,                           
        CalendarContract.Calendars.ACCOUNT_NAME,                  
        CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,         
        CalendarContract.Calendars.OWNER_ACCOUNT                  
};
private static final int PROJECTION_ID_INDEX = 0;
private static final int PROJECTION_ACCOUNT_NAME_INDEX = 1;
private static final int PROJECTION_DISPLAY_NAME_INDEX = 2;
private static final int PROJECTION_OWNER_ACCOUNT_INDEX = 3;

ContentResolver cr = getContentResolver();
Uri uri = CalendarContract.Calendars.CONTENT_URI;
String selection = "((" + CalendarContract.Calendars.ACCOUNT_NAME + " =?) AND (" + CalendarContract.Calendars.ACCOUNT_TYPE + " = ?) AND (" + CalendarContract.Calendars.OWNER_ACCOUNT + " = ?))";
String[] selectionArgs = new String[] {"hera@example.com", "com.example", "hera@example.com"};
 Cursor cur = cr.query(uri, EVENT_PROJECTION, selection, selectionArgs, null);
 while (cur.moveToNext()) {
    long calID = 0;
    String displayName = null;
    String accountName = null;
    String ownerName = null;

    calID = cur.getLong(PROJECTION_ID_INDEX);
    displayName = cur.getString(PROJECTION_DISPLAY_NAME_INDEX);
    accountName = cur.getString(PROJECTION_ACCOUNT_NAME_INDEX);
    ownerName = cur.getString(PROJECTION_OWNER_ACCOUNT_INDEX);
    }

我使用了来自android developer.com的示例,它仍然给我错误,我应该建立数据库而不是使用Uri吗?有人可以帮我吗?谢谢

These are the errors I got

0 个答案:

没有答案