Calendar-PhoneGap-Plugin icon indicating copy to clipboard operation
Calendar-PhoneGap-Plugin copied to clipboard

Events are saved as birthdays (Android 7)

Open teiermobi opened this issue 8 years ago • 9 comments

Hi,

i used this plugin in many different apps and never had any problems with it. But since i updated my phone to Android 7, every event i try to save in my calender is saved as a birthday and disappears from the calendar after one minute. On phones with an older android version everthing works as expected.

Maybe anyone can confirm this error or have a solution ?

Cheers, Tobi

teiermobi avatar Jan 11 '17 10:01 teiermobi

it seems that since android 7 createEvent() method will save the event to the default calendar "Contacts" that will cause the scenario you faced, try to use createEventWithOptions() with a particular calendar to save the event

gIt-SpLasHeR avatar Jan 16 '17 10:01 gIt-SpLasHeR

Thank you very much for your response. I tried everything you mentioned, but still with the same result. Every event i try to save is saved as a birthday for only a few seconds. Same thing when I use createEventWithOptions() and a own calendar.

Maybe someone else with an idea to solve this problem ? Cheers, Tobi

PS: Using Android 7.1.1

teiermobi avatar Jan 24 '17 08:01 teiermobi

@teiermobi even i am facing the same issue... did u figure out a way to resolve this issue?

kopimn avatar Mar 01 '17 12:03 kopimn

not sure if related or im just dumb, but same here on android 6. i have to use createEventInteractively() as ugly workaround. maybe related to the standard calendar? i have just google calendar connected.

michaelpapesch avatar Mar 06 '17 09:03 michaelpapesch

to give some more input, listCalendars gives me:

[{"id":"1","name":"Contacts"},{"id":"2","name":"Feiertage in Deutschland"},{"id":"4","name":"[email protected]"}]

@seducer0719 or anyone who knows: how can i use createEventWithOptions() in this case and find the "right" calendar to store dates in?

michaelpapesch avatar Mar 09 '17 10:03 michaelpapesch

hi,

sorry for my late response. I solved my problem by using createEventInteractively and calendarId: 1. But as @michaelpapesch said, it is an ugly workaround. Another solution is to get the device information of the user and if he is on android 7 use createEventWithOptions and calendarId: 3. If he is not you can save the event with the normal createEvent.

teiermobi avatar Mar 09 '17 11:03 teiermobi

well, as you can see, my calendarid would be 4, so i dont think you can just use a fixed number here.. createEvent() saves the entries in my contact list as birthdays on my 1+1 with Android 6.0.1 -.- anyways, interactively() shows the right calendar, so i guess thats my only option. my other problem was, that i have to add more than 1 date to the calendar, and to make this work, i had to call my addToCalendar-function recursively from its success-handler. problem here is, "cancel" when adding interactively() calls the success-handler on Android, but the error-handler on iOS, as it seems -.- well, i will care later about that.

my final code now is like this:

// dates is an array of objects having startCP as datetime from php
var dates;

// my postmessage handler, since the call comes from an iframe ebmedded in phonegap

window.addEventListener("message", function(event) {
          if (event.origin == domain) {
            if(event.data.event == "addCalender") {
              dates = event.data.data.dates;
              addToCalendar();
            }
          }
        },false);

function addToCalendar() {
  date = dates.shift();
  var startDate = new Date(date.startCP.date.replace(' ', 'T'));
  startDate.setHours(0,0,0,0);
  var eventLocation = "Frankfurt, Germany";
  if(platform=="iOS") {
    var endDate = new Date(startDate.getTime() + 86400000);
    } else {
    // full day cal entry on android needs the same start and end datetime. i guess thats a bug in the plugin
    var endDate = startDate;
    }
  var title = "My title";
  var notes = "My notes";
  var success = function(message) { if(dates.length>0) { addToCalendar(); } };
  var error = function(message) { alert("Error: " + message); };
  window.plugins.calendar.createEventInteractively(title,eventLocation,notes,startDate,endDate,success,error);
}

michaelpapesch avatar Mar 09 '17 11:03 michaelpapesch

I'm having this same issue here, but unfortunately listCalendars() doesn't output anything. Does anyone have some syntax I can look at and match? It's just a promise and I am handling it the same way I do other promises. Has anyone else run across this issue?

alexrindone avatar Oct 12 '17 00:10 alexrindone

To prevent events from being saved on the wrong calendar, you should prompt the user for which calendar to use. listCalendars() will output an isPrimary value for each calendar. If there is only one calendar with isPrimary, just save events to that one. If there are multiple, prompt. On iOS, you can check type = "CalDAV".

https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin/issues/464

terreng avatar Sep 12 '18 01:09 terreng