我想从我的应用中打开日历,并将参数“日期”传递给此日历。
此日历将显示日期的相应日期页面。
我调查了日历的源代码,但未找到使用方法。
public static void openCalendarApp(Context context)
{
Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.android.calendar");
context.startActivity(intent);
}
答案 0 :(得分:2)
您可以使用calendar view执行此操作...使用setDate(long date)
方法将日历上的日期设置为您想要的日期
你也可以通过向日历添加事件来实现这一点
创建日历的意图
Intent calIntent = new Intent(Intent.ACTION_INSERT);
calIntent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(calIntent)
播种日历日期和时间
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);
可以看到here
的示例答案 1 :(得分:0)
以下是如何支持Android的新旧版本:
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static Intent prepareIntentForCalendar(final Context context, final Date date) {
Intent intent = null;
if (VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
// go to date of the calendar app, as shown here:
// http://developer.android.com/guide/topics/providers/calendar-provider.html#intent-view
final Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, date.getTime());
intent = new Intent(Intent.ACTION_VIEW).setData(builder.build());
final PackageManager pm = context.getPackageManager();
final ResolveInfo resolveActivity = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY
| PackageManager.GET_RESOLVED_FILTER);
if (resolveActivity == null)
return null;
} else {
intent = new Intent(Intent.ACTION_EDIT);
intent.setClassName("com.android.calendar", "com.android.calendar.AgendaActivity");
intent.putExtra("beginTime", date.getTime());
final PackageManager pm = context.getPackageManager();
final ResolveInfo resolveActivity = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY
| PackageManager.GET_RESOLVED_FILTER);
if (resolveActivity == null)
intent = null;
}
if (intent != null)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY
| Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
return intent;
}