1

I was using this code to get event from calendar.

But I got error like this:

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

When debugging I noticed that code crash on this line:

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());

any idea will be helpful. Thanks.

Community
  • 1
  • 1
asish
  • 4,767
  • 4
  • 29
  • 49

1 Answers1

1

The error occurred for the OS version. May be you are using SDK-7. try this code instead,

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();
      }

This should work fine.

Shabib
  • 1,697
  • 4
  • 20
  • 39