Code example for ContentResolver

Methods: applyBatchquery

0
                .appendQueryParameter("account_name", account.name)
                .appendQueryParameter("account_type", account.type)
                .build();
         
         
        Cursor c1 = mContentResolver.query(calenderUri, new String[] { BaseColumns._ID }, null, null, null);
 
        if (c1.moveToNext() && !c1.isAfterLast()) {
            Log.d("XXXXXXX", "id = " + c1.getLong(0));
            return c1.getLong(0);
        } else { 
            ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
 
            ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(Calendars.CONTENT_URI.buildUpon()
                    .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                    .appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
                    .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
                    .build()
                    ); 
            builder.withValue(Calendars.ACCOUNT_NAME, account.name);
            builder.withValue(Calendars.ACCOUNT_TYPE, account.type);
            builder.withValue(Calendars.NAME, "LiquiDroid Events");
            builder.withValue(Calendars.CALENDAR_DISPLAY_NAME, "LiquiDroid Events");
            builder.withValue(Calendars.CALENDAR_COLOR, -5159922); // orange
            builder.withValue(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
            builder.withValue(Calendars.OWNER_ACCOUNT, account.name);
            builder.withValue(Calendars.SYNC_EVENTS, 1);
            operationList.add(builder.build());
             
            Log.d("XXX", builder.build().toString());
             
            try { 
                mContentResolver.applyBatch(CalendarContract.AUTHORITY, operationList);
            } catch (Exception e) {
                // TODO Auto-generated catch block 
                e.printStackTrace();
                return -1; 
            }