Android的默认日历ID

迪马·德赫蒂亚罗夫(Dima dehtiarov)

我正在尝试自动添加事件,但我需要为此添加日历ID如果我将事件添加到ID = 1的日历中,则有时它不存在或不依赖于我添加的事件

    ContentValues cv = new ContentValues();
    cv.put("calendar_id", 1);

id = -1 不起作用

如何将事件添加到默认日历。id应该使用什么?

亚历山大祖父
public MyCalendar [] getCalendar(Context c) {

String projection[] = {"_id", "calendar_displayName"};
Uri calendars;
calendars = Uri.parse("content://com.android.calendar/calendars");

ContentResolver contentResolver = c.getContentResolver();
Cursor managedCursor = contentResolver.query(calendars, projection, null, null, null);

if (managedCursor.moveToFirst()){
    m_calendars = new MyCalendar[managedCursor.getCount()];
    String calName;
    String calID;
    int cont= 0;
    int nameCol = managedCursor.getColumnIndex(projection[1]);
    int idCol = managedCursor.getColumnIndex(projection[0]);
    do {
        calName = managedCursor.getString(nameCol);
        calID = managedCursor.getString(idCol);
        m_calendars[cont] = new MyCalendar(calName, calID);
        cont++;
    } while(managedCursor.moveToNext());
    managedCursor.close();
}
return m_calendars;}

您可以尝试使用此代码获取日历ID。

但是请查看所有指南-如何将事件添加到日历。

https://stackoverflow.com/a/9749833/7046743

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章