2012-11-05 12 views
6

こんにちは、私はこのコードカレンダーからすべてのイベントを取得するには?

cur = null; 
    cr = getContentResolver(); 


    // Construct the query with the desired date range. 
    Uri.Builder builder = Instances.CONTENT_URI.buildUpon(); 

    ContentUris.appendId(builder, 0); 
    ContentUris.appendId(builder, endMillis); 


    // Submit the query 
    cur = cr.query(builder.build(), 
     INSTANCE_PROJECTION, 
     null, 
     null, 
     null); 

を使用してイベントを取得することができていますが、あなたは、私は与えられた時間内のみのイベントを取得することができます参照してください、私は(なし任意の時間指定が繰り返しイベントを除く)すべてのイベントを必要とされますこれは可能ですか?そしてどうやって ? 私を助けてください。

cur = cr.query(Uri.parse("content://com.android.calendar/events"), 
     INSTANCE_PROJECTION, 
     null, 
     null, 
     null); 

それはエラーjava.lang.IllegalArgumentExceptionがを与える:

+0

を確認することができます? – njzk2

答えて

10

は、このコードを試してみてください...

public class Utility { 

    public static ArrayList<String> nameOfEvent = new ArrayList<String>(); 
    public static ArrayList<String> startDates = new ArrayList<String>(); 
    public static ArrayList<String> endDates = new ArrayList<String>(); 
    public static ArrayList<String> descriptions = new ArrayList<String>(); 

    public static ArrayList<String> readCalendarEvent(Context context) { 
     Cursor cursor = context.getContentResolver() 
       .query(
         Uri.parse("content://com.android.calendar/events"), 
         new String[] { "calendar_id", "title", "description", 
           "dtstart", "dtend", "eventLocation" }, null, 
         null, null); 
     cursor.moveToFirst(); 
     // fetching calendars name 
     String CNames[] = new String[cursor.getCount()]; 

     // fetching calendars id 
     nameOfEvent.clear(); 
     startDates.clear(); 
     endDates.clear(); 
     descriptions.clear(); 
     for (int i = 0; i < CNames.length; i++) { 

      nameOfEvent.add(cursor.getString(1)); 
      startDates.add(getDate(Long.parseLong(cursor.getString(3)))); 
      endDates.add(getDate(Long.parseLong(cursor.getString(4)))); 
      descriptions.add(cursor.getString(2)); 
      CNames[i] = cursor.getString(1); 
      cursor.moveToNext(); 

     } 
     return nameOfEvent; 
    } 

    public static String getDate(long milliSeconds) { 
     SimpleDateFormat formatter = new SimpleDateFormat(
       "dd/MM/yyyy hh:mm:ss a"); 
     Calendar calendar = Calendar.getInstance(); 
     calendar.setTimeInMillis(milliSeconds); 
     return formatter.format(calendar.getTime()); 
    } 
} 

ます。また、インスタンスが何であるか、この

Getting events from calendar

+0

ありがとうございましたAmitが動作していません編集した質問を参照してください...... –

+0

http://stackoverflow.com/questions/4302209/android-calendar-events これをご覧ください –

+0

カレンダーを使用してListofattendeesを取得する方法 – Adevelopment

関連する問題