2012-04-18 32 views
1

我使用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

操作系统版本发生错误。可能你正在使用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(); 
     } 

这应该很好。

+1

谢谢,它工作:) – asish 2012-04-20 14:06:09