将CalendarView链接到设备日历

时间:2015-09-27 22:32:16

标签: android calendar

有没有办法将CalendarView小部件链接到移动设备上的内置日历?例如,当我点击CalendarView中的任何日期时,它会调出设备的Google日历,以便我可以设置提醒等等。

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_calendar_date);

    calendarView = (CalendarView)findViewById(R.id.calendar);


    calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
        @Override
        public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {

         //Could I place the code in here?
        }
    });
}

1 个答案:

答案 0 :(得分:1)

试试这个:

// Convert your year/month/day into date-time specified in milliseconds since the epoch.
long startMillis = ...
Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon();
builder.appendPath("time");
ContentUris.appendId(builder, startMillis);
Intent intent = new Intent(Intent.ACTION_VIEW)
    .setData(builder.build());
startActivity(intent);

Using intents to view calendar data | Calendar Provider | Android Developers