如何使用Intent(Froyo)启动Android日历应用程序

Man*_*rge 20 android calendar android-intent

我想从Android应用程序打开日历应用程序.当我在线搜索时,我得到的就是使用intent创建新事件.我可以找到Intents来打开Contacts和Gallery等.

是否可以将日历启动到特定的一周或一天?如果可能,有人可以帮助我.

提前致谢.

Muh*_*hab 20

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);
Run Code Online (Sandbox Code Playgroud)

  • @TijoKVarghese:确保您在Android手机而不是模拟器中运行或调试您的应用.我听说Android日历默认不会打包到模拟器图像中. (6认同)

DjP*_*DjP 9

您可以通过两种方式打开日历视图:

1)特定日期2)特定事件

为此,您必须添加以下两个权限

  <uses-permission android:name="android.permission.READ_CALENDAR" />
  <uses-permission android:name="android.permission.WRITE_CALENDAR" />
Run Code Online (Sandbox Code Playgroud)

1)按特定日期:

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);
Run Code Online (Sandbox Code Playgroud)

2)特定事件:

long eventID = 200;

Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, eventID);
Intent intent = new Intent(Intent.ACTION_VIEW).setData(uri);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

注意:CalendarContract内容提供商已添加到API级别14的Android SDK中.有关详细信息,请访问此链接