Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open android calendar app and jump to a specified date?

I want to open calendar from my app and pass parameter "Date" to this calendar.

And this calendar would display the Date's corresponding date page.

I have surveyed source code of calendar , but not found ways to use.

public static void openCalendarApp(Context context)
{   
    Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.android.calendar");
    context.startActivity(intent);
}
like image 706
user1921193 Avatar asked Oct 05 '22 13:10

user1921193


1 Answers

you can use the calendar view to do this... use the setDate(long date) method to set the date on the calendar to the date you want

you can also do this by adding events to the calendar like so

The intent to create a calendar

Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(calIntent)

Seeding Calendar Dates and Times

Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setType("vnd.android.cursor.item/event");
calIntent.putExtra(Events.TITLE, "Title here");
calIntent.putExtra(Events.EVENT_LOCATION, "Location here");
calIntent.putExtra(Events.DESCRIPTION, "Description here");
GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
     calDate.getTimeInMillis());
calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
     calDate.getTimeInMillis());
startActivity(calIntent);

an example of this can be seen here

like image 62
Hip Hip Array Avatar answered Oct 10 '22 02:10

Hip Hip Array