Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch Android Calendar application using Intent (Froyo)

Tags:

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.

like image 488
Manu George Avatar asked Dec 07 '10 03:12

Manu George


People also ask

What is Android intent Action view?

An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object.


2 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);
like image 92
Muhammad Shahab Avatar answered Nov 14 '22 23:11

Muhammad Shahab


You can open Calendar View by two means:

1) by particular date 2) by particular event

For this you have to add following two permissions

  <uses-permission android:name="android.permission.READ_CALENDAR" />
  <uses-permission android:name="android.permission.WRITE_CALENDAR" />

1) by particular date:

Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, Calendar.getInstance().getTimeInMillis());
Intent intent = new Intent(Intent.ACTION_VIEW)
    .setData(builder.build());
startActivity(intent);

2) by particular event:

long eventID = 200;

Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
Intent intent = new Intent(Intent.ACTION_VIEW).setData(uri);
startActivity(intent);

Note: CalendarContract content provider was added to the Android SDK in API Level 14. For more information you can visit this link

like image 38
DjP Avatar answered Nov 15 '22 01:11

DjP