android - How to Open Calendar App on a specific calendar -


i want open calendar application android application specific calendarid.

my code:

final intent calintent = new intent(intent.action_edit); calintent.settype("vnd.android.cursor.item/event");  startactivityforresult(calintent, result_code_open); 

but intent open last calendar used. want open specific 1 calendar id.

how can that?

a bit of history: looking calendar app sources, found this section of manifest indicates class handles intent.action_edit, editeventactivity.java. found this line; calendarid obtained data. so...

open editevent - (answer original question)

put long on intent key calendarcontract.events.calendar_id , corresponding calendarid sample:

long calendarid = 1234; // here goes calendar id  final intent calintent = new intent(intent.action_edit)        .settype("vnd.android.cursor.item/event")        .putextra(calendarcontract.events.calendar_id, calendarid);  startactivityforresult(calintent, result_code_open); 

open calendar app month week view on specific calendar - (answer bounty question - part 1)

this approach bit different. before open calendar app, should make invisible calendars no selected one. so, i've created helper function that.

private void makeallcalendarsinvisibleexcept(long calendarid) {     contentvalues updatevalues = new contentvalues();     updatevalues.put(calendarcontract.calendars.visible, 0);      // make invisible     getcontentresolver().update(calendarcontract.calendars.content_uri,             updatevalues, null, null);      updatevalues.clear();     updatevalues.put(calendarcontract.calendars.visible, 1);       // make calendarid visible     getcontentresolver().update(calendarcontract.calendars.content_uri,             updatevalues, where, null); } 

and here how setup it:

makeallcalendarsinvisibleexcept(calendarid); intent calintent = new intent(); // google calendar, first parameter should "com.google.android.calendar" // intended android calendar. componentname cn = new componentname("com.android.calendar", "com.android.calendar.launchactivity"); calintent.setcomponent(cn); startactivityforresult(calintent, 4567); 

afaik, no way open month view. research never ends, update asap.

in demoapp i've created 2 helper methods push , restore calendars visibility state. take arround pushcalendarvisibility , restorecalendarvisibility , onactivityresult

note: i've tested app , without google calendar installed. afaik on google calendar shown day view, not week neither month.

in cases shown events on selected calendar.

get calendarid , account name - (answer bounty question - part 2)

calendarid abd account name can obtained using calendarcontract.calendars, this:

// since api14  uri uri = calendarcontract.calendars.content_uri;  string[] projection = new string[] {         calendarcontract.calendars._id,         calendarcontract.calendars.visible,         calendarcontract.calendars.calendar_access_level,         calendarcontract.calendars.calendar_display_name,         calendarcontract.calendars.account_name, };  cursor calendarcursor = getcontentresolver().query(uri, projection, null, null, null); while (calendarcursor.movetonext()) {      // calendarid     long calendarid = calendarcursor.getlong(0);      // visibility, warning: if calendar not visible intent.action_edit doesn't work.     boolean calendarvisible = calendarcursor.getint(1) == 1;      // if it's owned, warning: if calendar not owned intent.action_edit doesn't work.     boolean calendarowned = calendarcursor.getint(2) == calendarcontract.calendars.cal_access_owner;      // calendar display name     string calendarname = calendarcursor.getstring(3);      // account name     string accountname = calendarcursor.getstring(4);      //  } 

note: there more available options calendar projection, advice read calendarcontract.calendars

limitations

this features available since api level 14, android 4.0 (ice_cream_sandwich)

demo app

complete example in this github repository. (android studio 1.0.0 project) requires calendars synced , must owned account , must visible. update: example date

tested on android 4.1.1 , android 5.0 lollipop preview


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -