[TIMOB-10540] Android: Map Calendar methods with Android permissions
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-01-25T22:02:27.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | Release 3.0.2, Release 3.1.0, 2012 Sprint 26 API, 2012 Sprint 26 |
Components | Android |
Labels | api, calendar, qe-testadded |
Reporter | Hieu Pham |
Assignee | Hieu Pham |
Created | 2012-08-21T17:55:40.000+0000 |
Updated | 2013-10-07T06:59:05.000+0000 |
Description
Assign "READ_CALENDAR" and/or "WRITE_CALENDAR" permissions with calendar methods appropriately in builder.py so permissions will be auto generated.
Steps to reproduce:
1. Run this code in Titanium Studio
Titanium.UI.setBackgroundColor('#000');
var win = Titanium.UI.createWindow({
title:'Calendar',
backgroundColor:'#fff'
});
win.open();
function showCalendars(calendars) {
for (var i = 0; i < calendars.length; i++) {
Ti.API.info(calendars[i].name);
Ti.API.info(JSON.stringify(calendars[i]));
}
}
Ti.API.info('ALL CALENDARS:');
showCalendars(Ti.Android.Calendar.allCalendars);
Ti.API.info('SELECTABLE CALENDARS:');
showCalendars(Ti.Android.Calendar.selectableCalendars);
// SHOW ALL EVENTS FOR 2010 FOR ONE CALENDAR
var YEAR = 2012;
var TEST_WITH_THIS_CAL_ID = 1;
var calendar = Ti.Android.Calendar.getCalendarById(TEST_WITH_THIS_CAL_ID);
var events = calendar.getEventsInYear(YEAR);
if (events && events.length) {
Ti.API.info(events.length + ' event(s) in ' + YEAR);
for (var i = 0; i < events.length; i++) {
Ti.API.info(JSON.stringify(events[i]));
}
} else {
Ti.API.info('No events');
}
var CALENDAR_TO_USE = 1;
var calendar = Ti.Android.Calendar.getCalendarById(CALENDAR_TO_USE);
// Create the event
var eventBegins = new Date(2012, 03, 26, 12, 0, 0);
var eventEnds = new Date(2012, 03, 26, 14, 0, 0);
var details = {
title: 'Do some stuff',
description: "I'm going to do some stuff at this time.",
begin: eventBegins,
end: eventEnds
};
var event = calendar.createEvent(details);
// Now add a reminder via e-mail for 10 minutes before the event.
var reminderDetails = {
minutes: 10,
method: Ti.Android.Calendar.METHOD_EMAIL
};
event.createReminder(reminderDetails);
2.Code should run w/o having to manually insert calendar permissions into tiapp.xml
Hieu, could you whip up a 3.0.x pull request and I'll review and merge that too?
Master PR: https://github.com/appcelerator/titanium_mobile/pull/3594
Backport Task TIMOB-12343 Backport PR https://github.com/appcelerator/titanium_mobile/pull/3734
If Calender permissions are not inserted into the tiapp.xml then Error occurs as " Exception occurred at app.js:53: Uncaught Error: Permission Denial: writing com.android.providers.calendar.CalendarProvider2 uri content://com.android.calendar/events from pid=2759, uid=10061 requires android.permission.WRITE_CALENDAR " Error occurs for sdk build : 3.1.0.v20130123144204, 3.0.2.v20130122172624 tested on Google Nexus Android version : 4.0.4
Master PR: https://github.com/appcelerator/titanium_mobile/pull/3787
Backport PR: https://github.com/appcelerator/titanium_mobile/pull/3788
Tested with: Titanium Studio, build: 3.0.2.201302011646 Titanium SDK, build: 3.0.2.v20130201161712 Device: Nexus4 Android version 4.2 "READ_CALENDAR" and/or "WRITE_CALENDAR" permissions are auto generated .