How to launch Android Calendar application using Intent (Froyo)

后端 未结 6 1379
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 02:00

I want to open up the Calendar application from an android application. When i searched online, all i got is to create new events using intent. I could find Intents to open

6条回答
  •  星月不相逢
    2020-12-01 02:01

    After reviewing the Calendar App in the Android source code you can only invoke the AgendaActivity directly. The others will not work. As the other posters have noted you can interact directly with the cursor to read/create events, but you can't invoke the calendar app to a view other than the AgendaView. The reason is that the developers have limited that ability in the manifest for the Cal app by using the following activity definitions:

        
        
        
        
    

    Note that only the AgendaActivity has android:exported="true". If you attempt to call the other activities you will get a permission exception.

    However, you can invoke the AgendaActivity to an arbitrary day with the following code:

        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);
    

提交回复
热议问题