微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Google Calendar API:将提醒更新为活动

我正在使用Google日历API.我已经从此代码添加了对事件的提醒

ContentValues values1 = new ContentValues();

values1.put("event_id", eventId);

values1.put("method", 1);

values1.put( "minutes", reminderValue );

Uri reminder = Uri.parse("content://com.android.calendar/reminders");

this.getContentResolver().insert(reminder, values1);

我的问题是我知道如何添加提醒..我需要查询更新提醒.通过此代码,它为事件添加了多个提醒.

请帮我.

谢谢

解决方法:

我认为您无法直接更新已设置的提醒.首先,您应该使用以下代码获取需要更新的提醒的ID:

String[] projection = new String[] {
        CalendarContract.Reminders._ID,
        CalendarContract.Reminders.METHOD,
        CalendarContract.Reminders.MINUTES
};

Cursor cursor = CalendarContract.Reminders.query(
    contentResolver, eventId, projection);
while (cursor.movetoNext()) {
    long reminderId = cursor.getLong(0);
    int method = cursor.getInt(1);
    int minutes = cursor.getInt(2);

    // etc.

}
cursor.close();

然后使用此提醒您必须使用以下代码删除已设置的提醒:

Uri reminderUri = ContentUris.withAppendedId(
CalendarContract.Reminders.CONTENT_URI, reminderId);
int rows = contentResolver.delete(reminderUri, null, null);

然后使用你的代码再次插入提醒.希望这有助于……

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐