package com.medikoe.connect.androidmedikoeconnect.utilities;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.net.Uri;
import android.provider.CalendarContract;
import android.widget.Toast;
import java.util.Date;
public class PushReminder {
private Activity activity;
public PushReminder(Activity activity) {
this.activity = activity;
}
public void addReminder(long startTime) throws SecurityException {
ContentResolver cr = activity.getContentResolver();
ContentValues calEvent = new ContentValues();
calEvent.put(CalendarContract.Events.CALENDAR_ID, 1); // XXX pick)
calEvent.put(CalendarContract.Events.TITLE, "Add Shop Reminder");
calEvent.put(CalendarContract.Events.DTSTART, startTime);
calEvent.put(CalendarContract.Events.DTEND, addMinutes(startTime));
calEvent.put(CalendarContract.Events.HAS_ALARM, 1);
calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, CalendarContract.Calendars.CALENDAR_TIME_ZONE);
Uri uri = cr.insert(CalendarContract.Events.CONTENT_URI, calEvent);
int id = Integer.parseInt(uri.getLastPathSegment());
Toast.makeText(activity, "Created Calendar Event " + id, Toast.LENGTH_SHORT).show();
ContentValues reminders = new ContentValues();
reminders.put(CalendarContract.Reminders.EVENT_ID, id);
reminders.put(CalendarContract.Reminders.METHOD, CalendarContract.Reminders.METHOD_ALERT);
reminders.put(CalendarContract.Reminders.MINUTES, 10);
Uri uri2 = cr.insert(CalendarContract.Reminders.CONTENT_URI, reminders);
Toast.makeText(activity, "Reminder have been saved succes fully", Toast.LENGTH_SHORT).show();
}
private long addMinutes(long time) {
Date date = new Date(time + 5 * 60 * 1000);
return date.getTime();
}
}
我正在尝试创建事件和提醒。我尝试保存提醒的那一刻,我遇到了此异常。
由以下原因导致:android.database.sqlite.SQLiteException android.database.DatabaseUtils.readExceptionFromParcel
它可以在某些手机上使用,而在某些手机上则不能。