Calendar permissions

802 views
Skip to first unread message

Carlos Verdier

unread,
May 24, 2017, 1:48:44 PM5/24/17
to CodenameOne Discussions
Hi

I'm trying to work with the cn1lib native calendar, but i'm not even able to set the permissions right on Android (not tried on iOS yet). This is what I write in codenameone_settings.properties

codename1.arg.android.xpermissions=<uses-permission android\:name\="android.permission.READ_CALENDAR"/><uses-permission android\:name\="android.permission.WRITE_CALENDAR"/><uses-permission android\:name\="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android\:name\="com.google.android.providers.gsf.permission.READ_GSERVICES"/><uses-feature         android\:glEsVersion\="0x00020000"         android\:required\="true"/>

And this is the exception I get:

[EDT] 0:0:18,357 - Exception: java.lang.SecurityException - Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{2cc3729 10745:es.vchmag/u0a372} (pid=10745, uid=10372) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR
java.lang.SecurityException: Permission Denial: opening provider com.android.providers.calendar.CalendarProvider2 from ProcessRecord{2cc3729 10745:es.vchmag/u0a372} (pid=10745, uid=10372) requires android.permission.READ_CALENDAR or android.permission.WRITE_CALENDAR
        at android.os.Parcel.readException(Parcel.java:1683)
        at android.os.Parcel.readException(Parcel.java:1636)
        at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:4241)
        at android.app.ActivityThread.acquireProvider(ActivityThread.java:5585)
        at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2262)
        at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1534)
        at android.content.ContentResolver.query(ContentResolver.java:519)
        at android.content.ContentResolver.query(ContentResolver.java:476)
        at com.codename1.c.a.a.a(AndroidCalendarImpl.java:79)
        at com.codename1.c.a.c.b(CalendarNativeInterfaceImpl.java:24)
        at com.codename1.c.a.d.b(CalendarNativeInterfaceStub.java:45)
        at com.codename1.c.a.c(DeviceCalendar.java:95)
        at d.a.a(StateMachine.java:2032)
        at d.a.a(StateMachine.java)
        at d.be.a(Unknown Source)
        at com.codename1.w.j.c.a(EventDispatcher.java:349)
        at com.codename1.w.e.a(Button.java:435)
        at com.codename1.w.e.b_(Button.java:467)
        at com.codename1.w.e.b(Button.java:566)
        at com.codename1.w.u.b(Form.java:2741)
        at com.codename1.w.p.b(Dialog.java:1718)
        at com.codename1.w.k.f(Component.java:3511)
        at com.codename1.w.q.m(Display.java:2026)
        at com.codename1.w.q.j(Display.java:1071)
        at com.codename1.w.q.a(Display.java:1208)
        at com.codename1.w.q.d(Display.java:1245)
        at com.codename1.w.u.a(Form.java:1898)
        at com.codename1.w.p.a(Dialog.java:1085)
        at com.codename1.w.p.a(Dialog.java:553)
        at com.codename1.w.p.a(Dialog.java:516)
        at d.a.a(StateMachine.java:2068)
        at d.a.a(StateMachine.java)
        at d.da.a(Unknown Source)
        at com.codename1.w.j.c.a(EventDispatcher.java:349)
        at com.codename1.w.e.a(Button.java:435)
        at com.codename1.w.e.b_(Button.java:467)
        at com.codename1.w.e.b(Button.java:566)
        at com.codename1.w.u.b(Form.java:2747)
        at com.codename1.w.u.b(Form.java:2680)
        at com.codename1.w.k.f(Component.java:3511)
        at com.codename1.w.q.m(Display.java:2026)
        at com.codename1.w.q.j(Display.java:1071)
        at com.codename1.w.q.i(Display.java:1000)
        at com.codename1.w.ag.run(RunnableWrapper.java:120)
        at com.codename1.impl.b$1.run(CodenameOneThread.java:60)
        at java
.lang.Thread.run(Thread.java:761)


The funny thing is that calendar.hasPermissions() returns true but calendar.getCalendars() fails.

Any ideas?

Shai Almog

unread,
May 25, 2017, 1:07:58 AM5/25/17
to CodenameOne Discussions
Hi,
check out this answer/workaround: https://stackoverflow.com/questions/43089357/android-calendar-permission-issue
Someone needs to update the calendar cn1lib

Carlos Verdier

unread,
May 25, 2017, 7:30:15 AM5/25/17
to CodenameOne Discussions
Thanks.

That partially solves the permission problem, but still calendar.getCalendars() returns null for me, so I guess the library is really outdated. I think I'll follow a different path, maybe local notification...

I think the library should be out of the plugins page until the issues are resolved, but this is a personal opinion.

Shai Almog

unread,
May 26, 2017, 12:27:51 AM5/26/17
to CodenameOne Discussions
That's a good point. Unfortunately removing it might make things worse (e.g. pushing update when it's fixed). I've added a note for this library, the littlemonkey QR scanner and the bluetooth library that explains this problem:
"Important: Currently requires Android API level 21 which might cause issues"

There isn't enough space there to go into details but hopefully this will alert users to the fact that these two libraries might have a problem.

Carlos Verdier

unread,
Jun 6, 2017, 1:07:03 PM6/6/17
to CodenameOne Discussions
I really needed this, so I've just sent a pull request to add Android 6 permissions. I have tested on my devices and it works fine.

Shai Almog

unread,
Jun 7, 2017, 12:45:31 AM6/7/17
to CodenameOne Discussions
I'll take a look at it. Ping me if I don't get this done this week

Carlos Verdier

unread,
Jun 7, 2017, 3:55:35 AM6/7/17
to CodenameOne Discussions
It's already merged.

This message should be removed now: 
Reply all
Reply to author
Forward
0 new messages