从日历获取事件的问题

时间:2012-04-18 13:21:08

标签: android calendar

我使用this代码从日历中获取活动。

但是我得到了错误

request time failed: java.net.SocketException: Address family not supported by protocol

调试时我注意到这行代码崩溃了:

Cursor eventCursor = contentResolver
                    .query(builder.build(), new String[]
                    { "title", "begin", "end", "allDay" },
                            "Calendars._id=" + 1, null,
                            "startDay ASC, startMinute ASC");

 System.out.println("eventCursor count=" + eventCursor.getCount());

任何想法都会有所帮助。感谢。

1 个答案:

答案 0 :(得分:1)

操作系统版本发生错误。可能是你在使用SDK-7。请尝试使用此代码,

Uri.Builder builder;
      if (android.os.Build.VERSION.SDK_INT <= 7)
      {
       // the old way
       builder = Uri.parse("content://calendar/instances/when").buildUpon();
      } else
      {
       // the new way
       builder = Uri
         .parse("content://com.android.calendar/instances/when").buildUpon();
      }

这应该可以正常工作。