2016-12-02 7 views
0

私と共有されているカレンダーにイベントを設定しようとしています。私はカレンダーのIDを使うべきであることを知っています。しかし、私は問題があります。ここに私のコードは次のとおりです。Android、共有カレンダーの場合IDを取得

作品とイベントがしかし、カレンダーのidのは分かっていない追加されている
@OnClick(R.id.add_event_button) 
    public void addEvent() { 

     CalendarDB calendar = (CalendarDB) mCalendarSpinner.getSelectedItem(); 
     Long id = calendar.getId(); 
     ContentValues event = new ContentValues(); 
     event.put("calendar_id", 1); 
     event.put(CalendarContract.Events.EVENT_TIMEZONE, "Europe/Berlin"); // Here choose your location time zone 
     event.put("title", "test application"); 
     event.put("description", "This is test event"); 
     event.put("eventLocation", "School"); 
     event.put("dtstart", System.currentTimeMillis()); 
     event.put("dtend", System.currentTimeMillis() + 1800 * 1000); 
     event.put("allDay", 0); 
     // status: 0~ tentative; 1~ confirmed; 2~ canceled 
     // event.put("eventStatus", 1); 
     event.put(CalendarContract.Events.CALENDAR_ID,8); 
     Uri l_eventUri; 
     if (Build.VERSION.SDK_INT >= 8) { 
      l_eventUri = Uri.parse("content://com.android.calendar/events"); 
     } else { 
      l_eventUri = Uri.parse("content://calendar/events"); 
     } 
     Uri l_uri = this.getContentResolver() 
       .insert(l_eventUri, event); 
     Toast.makeText(this, "SUCCESS", Toast.LENGTH_SHORT).show(); 

     } 

- 私はそれらを手動で設定しようと意味 - 1,2,3などとアウトにそれを把握しますカレンダーイベントが追加されます。 Google APIサイトでは、IDがLongである必要があります。カレンダーリストを取得すると、カレンダーのid-nameとして文字列が取得されています。同じ状況がandroid.provider CalendarContract.classである:

public static final String CALENDAR_ID = "calendar_id"; 

私は、パラメータのアプリがクラッシュしたように、そのIDを設定した場合 - それは長い引数を必要とします。では、共有カレンダーのIDを取得するにはどうすればよいですか?助けを事前に感謝:)

答えて

関連する問題