How can I open a calendar from my application?

I am creating an Android application, I do not need my application to be included in the calendar (plus it would defeat the goal), my application allows the user to listen to the radio station and needs the option to set the event (do not forget to listen to the radio at a certain time) if the application has its own calendar, then event alarms will be disabled only if the user opens the application ... pointless. I searched and can’t find if there is a way to use intention or something else to open a Google calendar or some other calendar that Android may have? I need to put my intention (/ other code) in my listener, which I already have, and now looks like this:

private View.OnClickListener reminder = new View.OnClickListener() { @Override public void onClick(View v) { // open calendar code goes here. } }; 

I do not need an application to pre-fill any field in the calendar, just open it, I will leave the rest to the user. all help is appreciated and thank you

+3
source share
1 answer

If you just want to open a calendar that you can use and intend to use EITHER from these component names (you may need to service both if you want to support older phones)

 Intent i = new Intent(); //Froyo or greater (mind you I just tested this on CM7 and the less than froyo one worked so it depends on the phone...) cn = new ComponentName("com.google.android.calendar", "com.android.calendar.LaunchActivity"); //less than Froyo cn = new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"); i.setComponent(cn); startActivity(i); 

If you want to go to the event adding screen (which is better suited for your purpose), use something like:

  //all version of android Intent i = new Intent(); // mimeType will popup the chooser any for any implementing application (eg the built in calendar or applications such as "Business calendar" i.setType("vnd.android.cursor.item/event"); // the time the event should start in millis. This example uses now as the start time and ends in 1 hour i.putExtra("beginTime", new Date().getTime()); i.putExtra("endTime", new Date().getTime() + DateUtils.HOUR_IN_MILLIS); // the action i.setAction(Intent.ACTION_EDIT); startActivity(i); 

(code not verified, copied from an existing project)

+9
source

Source: https://habr.com/ru/post/1487244/


All Articles