Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Calendar.findEvents missing id-filter #9

Closed
SjurWarEagle opened this issue Oct 28, 2016 · 4 comments
Closed

[Android] Calendar.findEvents missing id-filter #9

SjurWarEagle opened this issue Oct 28, 2016 · 4 comments
Labels
Milestone

Comments

@SjurWarEagle
Copy link

Hey,

I tried to load a freshly created event (the promise of create event returned "10"), so these options were given to findEvents:
JS: {"startDate":"1970-01-01T00:00:00.000Z","endDate":"2970-01-01T00:00:00.000Z","id":"10"}

According to the documentation:
/**
* Find events matched on ALL params passed in.
*/
this only should find id=10, but it lists every event for the time period. It looks like calendar.android.js is missing the check for the id in Calendar._findEvents line 130 following.

At the moment I cannot test if it works for ios but according to calendar.ios.js there is a check in Calendar.findEvents line 214.

Is this a bug, or is searching by id not supported on android? :)

Thanks for your support!

Torsten

@EddyVerbruggen
Copy link
Owner

You must be running an older version of the plugin as the line you refer to is no longer the same in version 1.1.1. Please upgrade/clean and let me know what happens :)

@SjurWarEagle
Copy link
Author

SjurWarEagle commented Oct 28, 2016

My bad, didn't notice the new version. Sorry!

The id-filter is working fine with that version, but the permission-requesting ist strange on android.
The popup for confirming the calendar-access pops up on every operation.
I'm creating a calendar entry -> popup, then calling findEvents -> popup.
When clicking in the app again on the button -> 2 popups.
hasPermissions() returns always false

Also rejecting the permissions crashes the app:

java.lang.RuntimeException: Unable to resume activity {de.hud.biff/com.tns.NativeScriptActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=123, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {de.hud.biff/com.tns.NativeScriptActivity}: com.tns.NativeScriptException:
Calling js method onRequestPermissionsResult failed

TypeError: Calendar._reject is not a function
File: "/data/data/de.hud.biff/files/app/tns_modules/nativescript-calendar/calendar.js, line: 26, column: 17

StackTrace:
Frame: function:'', file:'/data/data/de.hud.biff/files/app/tns_modules/nativescript-calendar/calendar.js', line: 26, column: 18
Frame: function:'Observable.notify', file:'/data/data/de.hud.biff/files/app/tns_modules/data/observable/observable.js', line: 158, column: 23
Frame: function:'ActivityCallbacksImplementation.onRequestPermissionsResult', file:'/data/data/de.hud.biff/files/app/tns_modules/ui/frame/fr [stacktrace cut off]

I guess I stay with 1.0.7 and filtering the id by hand. If you need any information, just contact me.

Greetings

Torsten

@SjurWarEagle
Copy link
Author

I added those loggings:

Calendar._hasPermission = function(perms) {
if (android.os.Build.VERSION.SDK_INT < 23) { // Android M. (6.0)
console.log("TKT 1");
return true;
}

var ctx = utils.ad.getApplicationContext();
console.log("TKT 2 perms "+JSON.stringify(perms));
for (var p in perms) {
var permission = perms[p];
console.log("TKT 2 permission "+JSON.stringify(permission));
console.log("TKT 2 ctx "+JSON.stringify(ctx));
console.log("TKT 2 checkSelfPermission "+JSON.stringify(android.support.v4.content.ContextCompat.checkSelfPermission(ctx, permission)));
if (android.content.pm.PackageManager.PERMISSION_GRANTED !== android.support.v4.content.ContextCompat.checkSelfPermission(ctx, permission)) {
console.log("TKT 2");
return false;
}
}
console.log("TKT 3");
return true;
};

This is the result:

"hasPermission call"

JS: TKT 2 perms ["android.permission.READ_CALENDAR","android.permission.WRITE_CALENDAR"]
JS: TKT 2 permission "android.permission.READ_CALENDAR"
JS: TKT 2 ctx {}
JS: TKT 2 checkSelfPermission -1
JS: TKT 2
JS: has permission

"createEvent call"

JS: TKT 2 perms "android.permission.WRITE_CALENDAR"
JS: TKT 2 permission "a" <-----
JS: TKT 2 ctx {}
JS: TKT 2 checkSelfPermission -1
JS: TKT 2
JS: ---- created event with id: 18

"findEvents call"

JS: {"startDate":"1970-01-01T00:00:00.000Z","endDate":"2286-11-20T17:46:39.999Z","id":"18"}
JS: TKT 2 perms "android.permission.READ_CALENDAR"
JS: TKT 2 permission "a" <-----
JS: TKT 2 ctx {}
JS: TKT 2 checkSelfPermission -1
JS: TKT 2
JS: foundEvents: [{"id":18,"title"...

The problem is this:

Calendar._hasReadPermission = function() {
return Calendar._hasPermission(android.Manifest.permission.READ_CALENDAR);
};

Calendar._hasWritePermission = function() {
return Calendar._hasPermission(android.Manifest.permission.WRITE_CALENDAR);
};

you are calling the check-method with a string and not with an array. After changing it to

Calendar._hasReadPermission = function() {
return Calendar._hasPermission([android.Manifest.permission.READ_CALENDAR]);
};

Calendar._hasWritePermission = function() {
return Calendar._hasPermission([android.Manifest.permission.WRITE_CALENDAR]);
};

it works better. Now the popup still appears twice (once for read and one for write) but after this, it never appears again.

@EddyVerbruggen
Copy link
Owner

EddyVerbruggen commented Oct 29, 2016

You are right, that should have been an array! That's fixed now. Available in 1.1.2.

About the 2 prompts: the plugin is asking permission for the action it wants to perform, so for find it only needs read permission. If you later want to also create an event you need permission to write as well.

If your app wants to do both things you can invoke the hasPermission and requestPermission functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants