I want to open up the Calendar application from an

2019-05-27 05:15发布

问题:

I want to open up the Calendar application from an android application. When i searched online, all i got this code.but it didn't work the below android 2.1. Is it possible to launch Calender application from an android application below 2.1? If possible, could someone please help me with it.

Calendar tempCal = (Calendar) mCalendar.clone();
    tempCal.set(year, month, day); 
    Intent calendarIntent = new Intent() ;
    calendarIntent.putExtra("beginTime", tempCal.getTimeInMillis());
    calendarIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    calendarIntent.setClassName("com.android.calendar","com.android.calendar.AgendaActivity");
    startActivity(calendarIntent);

回答1:

I also recommend this: How to launch Android Calendar application using Intent (Froyo)



回答2:

Intent intent = new Intent(Intent.ACTION_EDIT);  

intent.setType("vnd.android.cursor.item/event");

intent.putExtra("title", "Some title");

intent.putExtra("description", "Some description");

intent.putExtra("beginTime", eventStartInMillis);

intent.putExtra("endTime", eventEndInMillis);

startActivity(intent);


回答3:

To launch the activity for adding an event to the calendar, use:

    Intent intent = new Intent();

    intent.setType("vnd.android.cursor.item/event"); 
    intent.putExtra("beginTime", startTimeInMilliseconds); 
    intent.putExtra("endTime", endTimeInMilliseconds);

    intent.setAction(Intent.ACTION_EDIT);
    startActivity(intent);