1

Googleカレンダーに挿入した後でレコードを読み取ることができません。Googleカレンダーに挿入した後にレコードを読み取ることができません

いくつかの時間文字は、レコードが読み取られます。

なぜですか?

ContextActivityから取り除くと、すべて正常に機能します。 ContextからAndroidTestCaseになるか、またはApplicationを使用すると動作しません。

注:id = calendarIdのカレンダーは空です。

public static void test(final Context context, final int calendarId) { 
    // insert 
    java.util.Calendar calendar = java.util.Calendar.getInstance(); 

    ContentValues contentValues = new ContentValues(); 

    contentValues.put("calendar_id", calendarId); 
    contentValues.put("dtstart", calendar.getTime().getTime()); 
    contentValues.put("dtend", calendar.getTime().getTime() + 1L*60*60*1000); 
    contentValues.put("title", "test_title"); 

    Uri uri = Uri.parse("content://com.android.calendar/events"); 
    context.getContentResolver.insert(uri, contentValues); 

    // read 
    Uri.Builder builder = Uri.parse("content://com.android.calendar/instances/when").buildUpon(); 
    ContentUris.appendId(builder, Long.MIN_VALUE); 
    ContentUris.appendId(builder, Long.MAX_VALUE); 

    Cursor cursor = context.getContentResolver.query(
     builder.build(), 
     new String[] { "event_id", "title" }, 
     "Calendars._id=" + calendarId, 
     null, 
     null); 
    try { 
     if (!cursor.moveToNext()) { 
      // fail 
      throw new IllegalStateException(); 
     } 
    } finally { 
     cursor.close(); 
    } 
} 

答えて

0

私の間違い。コード内値を設定できません。

関連する問題