EddyVerbruggen / Calendar-PhoneGap-Plugin

:date: Cordova plugin to Create, Change, Delete and Find Events in the native Calendar
774 stars 402 forks source link

App crashed after adding event to calendar with "createEventInteractively" #399

Open SerhiiZiatko opened 7 years ago

SerhiiZiatko commented 7 years ago

Hi, could you help me? I'm trying to use "createEventInteractively" method to add an event to a calendar in my app, but after adding an event the app is being crashed (Android 6.0.1, Xiaomi Redmi 4 pro). This is a log of the error

java.lang.RuntimeException: Unable to resume activity {com.hoppity.dental99/com.hoppity.dental99.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=0, data=null} to activity {com.hoppity.dental99/com.hoppity.dental99.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success()' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3110) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3141) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2488) at android.app.ActivityThread.access$900(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5441) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=0, data=null} to activity {com.hoppity.dental99/com.hoppity.dental99.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success()' on a null object reference at android.app.ActivityThread.deliverResults(ActivityThread.java:3706) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3096) ... 10 more Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CallbackContext.success()' on a null object reference at nl.xservices.plugins.Calendar.onActivityResult(Calendar.java:645) at org.apache.cordova.CordovaInterfaceImpl.onActivityResult(CordovaInterfaceImpl.java:152) at org.apache.cordova.CordovaActivity.onActivityResult(CordovaActivity.java:358) at android.app.Activity.dispatchActivityResult(Activity.java:6508) at android.app.ActivityThread.deliverResults(ActivityThread.java:3702) ... 11 more

this is my implementation of this functional

addToCalendar() { this.calendar.hasWritePermission().then(res => { if (res) { this.createEvent(); return; } this.calendar.requestWritePermission().then(res => { if (res) { this.createEvent(); return; } }) }) }

createEvent() { const event = this.generateEvent(); this.calendar.createEventInteractively(event.title, event.location, event.notes, event.startDate, event.endDate) .then((id) => { this.view.successToast('Appointment was added to your calendar') this.trackApptAddedToCalendar(); }) .catch(err => { this.view.errorToast(err) }); }

this is my ionic environment

global packages:

@ionic/cli-utils : 1.3.0
Cordova CLI      : 6.5.0
Ionic CLI        : 3.3.0

local packages:

@ionic/app-scripts              : 1.3.7
@ionic/cli-plugin-cordova       : 1.3.0
@ionic/cli-plugin-ionic-angular : 1.3.0
Cordova Platforms               : android 6.1.2 ios 4.4.0
Ionic Framework                 : ionic-angular 3.3.0

System:

Node       : v7.8.0
OS         : macOS Sierra
Xcode      : Xcode 8.3.1 Build version 8E1000a
ios-deploy : 1.9.1
ios-sim    : 5.0.13

Thank you:)

Webjin commented 3 years ago

Any updates on this issue?

IEEE-Ray commented 2 months ago

Hello esoteric bug hunters! So I recently experience this issue and as of now there is virtually no solution. Or at least on the side of the developer.

The issue is with the calendar app on Xiaomi Redmi. It is built by the company rather than Google Calendar and it has some memory problems. When I tried to opening just the calendar app that was on the device without it being invoked from my app, it briefly showed all the events I added before crashing. This is a sign that the cordova plugin successfully added things but that the calendar app itself is the problem. When investigating further the calendar crash on Redmi devices, some people have posted this issue and share that it was resolved by going to settings --> apps --> calendar --> storage --> clear cache.

I unfortunately could not try this solution on BrowserStack but maybe someone else can validate this. I would have loved the resolution to be some clever line of code but as of now my manager and I have accepted that some bugs are beyond our scope of control.