martes, 1 de enero de 2013

Llamar el Calendario de Android desde nuestra aplicación.

URL ORIGEN: http://stackoverflow.com/questions/4373074/how-to-launch-android-calendar-application-using-intent-froyo


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 Contacts and Gallery etc.
Is it possible to launch the Calendar to a specific week or day? If possible, could someone please help me with it.
Thanks in advance.
share|improve this question
I tried, but it gave me a permission denied exception – Mohit Verma Apr 2 '12 at 7:48
Was this post useful to you?     

4 Answers

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);
share|improve this answer
when i tried this i got the following error..Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT typ=vnd.android.cursor.item/event (has extras) }..could you please give a solution on this.? – Tijo K Varghese Jan 5 '12 at 12:10
3 
@TijoKVarghese : Make sure you're running or debugging your app in a Android phone instead of emulator. I heard Android Calendar is not defaultly packed into emulator image. – Evi Song Jan 10 '12 at 10:58
ok..i will check this with actual device..till now i had tested only on android emulator. – Tijo K Varghese Jan 10 '12 at 11:23
feedback
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:
    <activity android:name="MonthActivity" android:label="@string/month_view"
        android:theme="@style/CalendarTheme" />
    <activity android:name="WeekActivity" android:label="@string/week_view"
        android:theme="@style/CalendarTheme" />
    <activity android:label="@string/day_view" android:name="DayActivity"     
        android:theme="@style/CalendarTheme"/>
    <activity android:name="AgendaActivity" android:label="@string/agenda_view"
        android:theme="@android:style/Theme.Light"
        android:exported="true" />
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);
share|improve this answer
feedback
AgendaActivity loads the "Agenda" view.
From my experience you can't deep link into the Day, Week and Month activities in stock Android, however you can use "LaunchActivity" which loads the last opened view.
share|improve this answer
feedback
By a process of tedious experimentation, I've found that:
Intent calendarIntent = new Intent() ;
calendarIntent.setClassName("com.android.calendar","com.android.calendar.AgendaActivity");
...works for me to launch the Calendar's Agenda Activity. Haven't tried, but perhaps com.android.calendar.DayActivity, .WeekActivity,and .MonthActivity will launch the corresponding Activities.

No hay comentarios:

Publicar un comentario