ContentResolver applyBatch - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for ContentResolver applyBatch method.

This code example shows how to use the following methods:applyBatch
        operations.add(ContentProviderOperation.newUpdate(rawContactDataUri)
                .withSelection(Photo.MIMETYPE + "=?", new String[] {Photo.CONTENT_ITEM_TYPE})
                .withValues(values).build());
 
        try { 
            mContentResolver.applyBatch(ContactsContract.AUTHORITY, operations);
        } catch (RemoteException e) {
            throw new IllegalStateException("Problem querying raw_contacts/data", e);
        } catch (OperationApplicationException e) {
            if (allowInsert) {
                // they deleted the photo between insert and update, so insert one 
                insertPhoto(values, rawContactDataUri, false);
            } else { 
                throw new IllegalStateException("Problem inserting photo raw_contacts/data", e);
            } 
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:applyBatch
     * {@link android.content.ContentProviderOperation} that are immediately applied using the 
     * given {@link android.content.ContentResolver}. 
     */ 
    public void parseAndApply(ArrayList<JSONArray> entries, ContentResolver resolver) throws JSONHandlerException {
    	try { 
	        final ArrayList<ContentProviderOperation> batch = parse(entries, resolver);
	        resolver.applyBatch(getAuthority(), batch);
        } catch (JSONException e) {
            throw new JSONHandlerException("Problem parsing JSON response", e);
        } catch (RemoteException e) {
            throw new RuntimeException("Problem applying batch operation", e);
        } catch (OperationApplicationException e) {
            throw new RuntimeException("Problem applying batch operation", e);
        } 
    } 
	                                                           //application/json 
    /** 
     * Parse the given {@link JSONHandler}, returning a set of 
     * {@link android.content.ContentProviderOperation} that will bring the 
     * {@link android.content.ContentProvider} into sync with the parsed data. 
5
CodeRank
This code example shows how to use the following methods:applyBatch
		if (mOperations.size() == 0) {
			return result;
		} 
		// Apply the mOperations to the content provider 
		try { 
			ContentProviderResult[] results = mResolver.applyBatch(
					ContactsContract.AUTHORITY, mOperations);
			if ((results != null) && (results.length > 0))
				result = results[0].uri;
		} catch (final OperationApplicationException e1) {
			Log.e(TAG, "storing contact data failed", e1);
		} catch (final RemoteException e2) {
			Log.e(TAG, "storing contact data failed", e2);
		} 
		mOperations.clear();
		return result;
	} 
} 
5
CodeRank
This code example shows how to use the following methods:applyBatch
	 * Parse the given {@link org.json.JSONArray}, turning into a series of {@link android.content.ContentProviderOperation} that are immediately applied using 
	 * the given {@link android.content.ContentResolver}. 
	 */ 
	public void parseAndApply(ArrayList<JSONArray> entries, ContentResolver resolver) throws JsonHandlerException {
		try { 
			final ArrayList<ContentProviderOperation> batch = parse(entries, resolver);
			resolver.applyBatch(authority, batch);
		} catch (JSONException e) {
			throw new JsonHandlerException("Problem parsing JSON response", e);
		} catch (RemoteException e) {
			throw new RuntimeException("Problem applying batch operation", e);
		} catch (OperationApplicationException e) {
			throw new RuntimeException("Problem applying batch operation", e);
		} 
	} 
 
	/** 
	 * Parse the given {@link JSONHandler}, returning a set of {@link android.content.ContentProviderOperation} that will bring the 
	 * {@link android.content.ContentProvider} into sync with the parsed data. 
	 */ 
5
CodeRank
This code example shows how to use the following methods:applyBatch
     * @throws HandlerException 
     */ 
    public void parseAndApply(String jsonString, ContentResolver resolver)
            throws HandlerException { 
        try { 
            final ArrayList<ContentProviderOperation> batch = parse(jsonString, resolver);
            resolver.applyBatch(mAuthority, batch);
 
        } catch (HandlerException e) {
            throw e;
        } catch (JSONException e) {
            e.printStackTrace();
            throw new HandlerException("Problem parsing JSON response", e);
        } catch (IOException e) {
            throw new HandlerException("Problem reading response", e);
        } catch (RemoteException e) {
            // Failed binder transactions aren't recoverable 
            throw new RuntimeException("Problem applying batch operation", e);
        } catch (OperationApplicationException e) {
            // Failures like constraint violation aren't recoverable 
5
CodeRank
This code example shows how to use the following methods:applyBatch
     * given {@link ContentResolver}. 
     */ 
    public void parseAndApply(XmlPullParser parser, ContentResolver resolver)
            throws HandlerException { 
        try { 
            final ArrayList<ContentProviderOperation> batch = parse(parser, resolver);
            resolver.applyBatch(mAuthority, batch);
 
        } catch (HandlerException e) {
            throw e;
        } catch (XmlPullParserException e) {
            throw new HandlerException("Problem parsing XML response", e);
        } catch (IOException e) {
            throw new HandlerException("Problem reading response", e);
        } catch (RemoteException e) {
            // Failed binder transactions aren't recoverable 
            throw new RuntimeException("Problem applying batch operation", e);
        } catch (OperationApplicationException e) {
            // Failures like constraint violation aren't recoverable 
            // TODO: write unit tests to exercise full provider 
5
CodeRank
This code example shows how to use the following methods:applyBatch
                .withValue(Groups.ACCOUNT_NAME, account.name)
                .withValue(Groups.ACCOUNT_TYPE, account.type)
                .withValue(Groups.GROUP_VISIBLE, 1).build());
 
        try { 
            ContentProviderResult[] results = contentResolver.applyBatch(
                    ContactsContract.AUTHORITY, batch);
            long id = ContentUris.parseId(results[0].uri);
 
            Log.d(TAG, format("Group {0} was created.", uid));
            return SyncedGroup.create(id, uid, title);
        } catch (Exception exception) {
            throw new SyncOperationException(format(
                    "Could not create group {0}.", uid), exception);
        } 
    } 
 
    /** 
     * Updates title of group. 
     *  
4
CodeRank
This code example shows how to use the following methods:applyBatch
        if (mOperations.size() == 0) {
            return; 
        } 
        // Apply the mOperations to the content provider 
        try { 
            mResolver.applyBatch(ContactsContract.AUTHORITY, mOperations);
        } catch (final OperationApplicationException e1) {
            Log.e(TAG, "storing contact data failed", e1);
        } catch (final RemoteException e2) {
            Log.e(TAG, "storing contact data failed", e2);
        } 
        mOperations.clear();
    } 
 
} 
4
CodeRank
This code example shows how to use the following methods:applyBatch
        if (mOperations.size() == 0) {
            return; 
        } 
        // Apply the mOperations to the content provider 
        try { 
            mResolver.applyBatch(ContactsContract.AUTHORITY, mOperations);
        } catch (final OperationApplicationException e1) {
            Log.e(TAG, "storing contact data failed", e1);
        } catch (final RemoteException e2) {
            Log.e(TAG, "storing contact data failed", e2);
        } 
        mOperations.clear();
    } 
 
} 
4
CodeRank
This code example shows how to use the following methods:applyBatch
        if (mOperations.size() == 0 || mOperations == null || mResolver == null) {
            return; 
        } 
        // Apply the mOperations to the content provider 
        try { 
            mResolver.applyBatch(ContactsContract.AUTHORITY, mOperations);
        } catch (final OperationApplicationException e1) {
            Log.e(TAG, "storing contact data failed", e1);
        } catch (final RemoteException e2) {
            Log.e(TAG, "storing contact data failed", e2);
        } 
        mOperations.clear();
    } 
 
} 
4
CodeRank

Related ContentResolver applyBatch Questions & Answers:

applyBatch Method Overview
Applies each of the ContentProviderOperation objects and returns an array of their results.
See Code Examples for other Android ContentResolver Methods: