Google Calendar Entry Alarm не работает Android - PullRequest
1 голос
/ 04 января 2011

Мне нужно установить будильник в календаре Google через приложение для Android.Я успешно ввел данные в календарь, хотя он показывает, что будильник тоже был установлен, но когда я просматриваю детали записи в календаре, он автоматически удаляет настройки будильника.

, пожалуйста, сообщите, ниже приведен фрагмент кода.

private Uri MakeNewCalendarEntry(int calId, String title, String desc,
        String location, String matchDate) {
    ContentValues event = new ContentValues();

    String value = matchDate;
    String[] splitedTimeDate = value.split("T");

    String dateValue = splitedTimeDate[0];
    String[] timeValue = splitedTimeDate[1].split("-");

    matchDate = dateValue + " " + timeValue[0];

    event.put("calendar_id", calId);
    event.put("title", title);
    event.put("description", desc);
    event.put("eventLocation", location);

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    java.util.Date d = null;
    try {
        d = formatter.parse(matchDate);// catch exception
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // This is the UTC Event Start Date
    Calendar calUTCEventDate = Calendar.getInstance();
    calUTCEventDate.setTime(d); // rest is the same....

    // This is the current UTC Date
    Calendar calCurrentUTCDate = Calendar.getInstance();

    TimeZone z = calCurrentUTCDate.getTimeZone();
    int offset = z.getRawOffset();
    int offsetHrs = offset / 1000 / 60 / 60;
    int offsetMins = offset / 1000 / 60 % 60;

    calCurrentUTCDate.add(Calendar.HOUR_OF_DAY, (-offsetHrs));
    calCurrentUTCDate.add(Calendar.MINUTE, (-offsetMins));

    // This is the current Device Date
    Calendar calCurrentDeviceDate = Calendar.getInstance();

    long diff = calUTCEventDate.getTimeInMillis()
            - calCurrentUTCDate.getTimeInMillis();
    long minutes = Math.abs(diff) / (1000 * 60);
    long hours = minutes / 60;

    long startTime = System.currentTimeMillis() + 1000 * 60 * 60 * hours;
    long endTime = System.currentTimeMillis() + 1000 * 60 * 60
            * (hours + 8);

    event.put("dtstart", startTime);
    event.put("dtend", endTime);

    event.put("allDay", 0); // 0 for false, 1 for true
    event.put("eventStatus", 1);
    event.put("visibility", 1);
    event.put("transparency", 0);
    event.put("hasAlarm", 1); // 0 for false, 1 for true


    Uri eventsUri = Uri.parse(getCalendarUriBase() + "events");

    Uri insertedUri = getContentResolver().insert(eventsUri, event);
    return insertedUri;
}

Ответы [ 2 ]

3 голосов
/ 28 января 2011

Ниже фрагмент помог мне решить проблему ...

Blockquote // Вышеупомянутый фрагмент кода возвращает мне событие Id

            Uri newEvent = MakeNewCalendarEntry(iTestCalendarID, title,
                    desc, location, matchDate);
            int eventID = Integer.parseInt(newEvent.getLastPathSegment());

Blockquote

            final ContentResolver cr = getContentResolver();
            ContentValues values = new ContentValues();
            values.put("event_id", eventID);
            values.put("method", 1);
            values.put("minutes", 5);
            cr.insert(Uri.parse("content://com.android.calendar/reminders"), values); // for android 2.2+

          // OR 

            cr.insert(Uri.parse("content://calendar/reminders"), values); // for android 2.1 n earlier

спасибо

-y

0 голосов
/ 02 мая 2011

Я использую GCalendar Widget для просмотра, создания, редактирования и удаления событий Календаря Google.

http://bstdownload.com/reviews/gcalendar-widget-1/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...