mercredi 15 avril 2015

Android local calender id

I'm adding, updating, deleting events using local calendar. I'm using this code to get local calendar id:



private static long getCalendarId(Context context) {
String[] projection = new String[]{CalendarContract.Calendars._ID};
String selection = CalendarContract.Calendars.ACCOUNT_TYPE + " = ? ";
String[] selArgs = new String[]{CalendarContract.ACCOUNT_TYPE_LOCAL};

Cursor cursor = context.getContentResolver().
query(CalendarContract.Calendars.CONTENT_URI, projection,
selection, selArgs, null);

if (cursor.moveToFirst()) {
return cursor.getLong(0);
}

return -1;
}


Is there a case that -1 is returned? like not having local calendar on some devices/OSs, or being deleted by the user, or some other reason? If this is not safe please provide an alternative. Thanks.


Aucun commentaire:

Enregistrer un commentaire