2015-11-13 31 views
0

我有一個CalendarView。當按下一個日期,應用程序打開了該設備的具體日期的日曆被點擊:CalendarView到設備日曆鏈接

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

      cal.set(year,month,dayOfMonth); 

      long epochMillis = cal.getTimeInMillis(); 

      Uri.Builder uriBuilder = CalendarContract.CONTENT_URI.buildUpon(); 
      uriBuilder.appendPath("time"); 
      ContentUris.appendId(uriBuilder, epochMillis); 
      Uri uri = uriBuilder.build(); 

      Intent i = new Intent(Intent.ACTION_VIEW); 
      i.setData(uri); 
      startActivity(i); 

     } 
    }); 

這工作得很好。我的問題是,有沒有辦法讓用戶進入「創建事件屏幕」,而不是它現在帶給我的位置,這是整個月的所選日期突出顯示的視圖?我希望他們能夠點擊我的CalendarView中的日期,並將其帶到設備日曆上的屏幕上,以便他們將約會添加到所選日期。想知道是否有人知道該屏幕的uri是什麼?謝謝。

回答

0

我終於明白了。兩件事情。

  1. 我正在追加「時間」到我的URI。這將簡單地打開日曆,直到我在啓動意圖時指定的特定時間。爲了打開特定日期的事件屏幕,我需要追加「事件」。

  2. 當我創建intent時,我使用了ACTION_VIEW。相反,我需要ACTION_INSERT。

    calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() { 
    @Override 
    public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) { 
        cal = Calendar.getInstance(); 
    
        cal.set(year,month,dayOfMonth); 
    
        long epochMillis = cal.getTimeInMillis(); 
    
        Uri.Builder uriBuilder = CalendarContract.CONTENT_URI.buildUpon(); 
        uriBuilder.appendPath("events"); 
    
        Uri uri = uriBuilder.build(); 
    
        Intent i = new Intent(Intent.ACTION_INSERT); 
        i.setData(uri); 
        i.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, epochMillis); 
        startActivity(i); 
    
    }}); 
    
:我然後使用我的新的URI,其中包括「事件」,然後指定一個開始時間,這是我想要的特定日期設定的意圖的數據