24.1.11

Failed to find provider info for Calendar, Unknown URL content://calendar/events Android


Failed to find provider info for Calendar,
Unknown URL content://calendar/events
Android

Hi, if you are reading this, probably you are getting an error on Android 2.0 and above OS when adding calendar event.

And probably that peace of code that was working fine for Android 1.6, not is throwing error for android 2.0 and above versions.

You should know, that, on new Android versions the URI for Calendar content provider has changed,now you should use content://com.android.calendar/

Yes it´s a crap :(

So, if you was using content://calendar/ , to get successful, you should use content://com.android.calendar/

If you want to maintain a compatibility across all Android versions of your apps,
you will need to handle the Old URI along with the New URI, you can do something like this:


Uri calendarUri;
Uri eventUri;
if (android.os.Build.VERSION.SDK_INT <= 7 )
{
  //the old way
  calendarUri = Uri.parse("content://calendar/calendars"); 
  eventUri    = Uri.parse("content://calendar/events");
}
else
{
 //the new way
 calendarUri = Uri.parse("content://com.android.calendar/calendars");
 eventUri    = Uri.parse("content://com.android.calendar/events");
} 

But, lets play a bit xDDD


funtcion Uri getCalendarURI(eventUri boolean){
Uri calendarURI = null;

    if (android.os.Build.VERSION.SDK_INT <= 7 )
    {
         calendarURI = (eventUri)?Uri.parse("content://calendar/events"):Uri.parse("content://calendar/calendars");
    }
    else
        {
        calendarURI = (eventUri)?Uri.parse("content://com.android.calendar/events"): Uri.parse("content://com.android.calendar/calendars");
    } 
 return calendarURI; 
}

Or in one line :


function Uri getCalendarUri(eventUri boolean){
    return  (android.os.Build.VERSION.SDK_INT <= 7 )?((eventUri)?Uri.parse("content://calendar/events"):Uri.parse("content://calendar/calendars")):(calendarURI = (eventUri)?Uri.parse("content://com.android.calendar/events"): Uri.parse("content://com.android.calendar/calendars"));
}


And that's all folks ;)

Note : android.os.Build.VERSION.SDK_INT is available since SDK_INT = 4 i mean Android 1.6,for prior versions check android.os.Build.VERSION.SDK more info at http://developer.android.com/reference/android/os/Build.VERSION

Creative Commons License This page is powered by Blogger. Isn't yours?