android.content.ContentProviderResult Java Examples
The following examples show how to use
android.content.ContentProviderResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentProviderProxy1.java From Neptune with Apache License 2.0 | 6 votes |
@Override public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { if (operations.size() > 0) { ContentProvider provider = getContentProvider(operations.get(0).getUri()); if (provider != null) { try { for (ContentProviderOperation operation : operations) { Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(IntentConstant.EXTRA_TARGET_URI_KEY)); ReflectionUtils.on(operation).set("mUri", pluginUri); } return provider.applyBatch(operations); } catch (Exception e) { return new ContentProviderResult[0]; } } } return new ContentProviderResult[0]; }
Example #2
Source File: DataProvider.java From callmeter with GNU General Public License v3.0 | 6 votes |
@Override public ContentProviderResult[] applyBatch( @NonNull final ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { Log.d(TAG, "applyBatch(#", operations.size(), ")"); ContentProviderResult[] ret = null; final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); assert db != null; db.beginTransaction(); try { ret = super.applyBatch(operations); db.setTransactionSuccessful(); } catch (SQLException e) { Log.e(TAG, "error applying batch"); throw e; } finally { db.endTransaction(); } return ret; }
Example #3
Source File: V2exProvider.java From v2ex with Apache License 2.0 | 6 votes |
@Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { final int numOperations = operations.size(); final ContentProviderResult[] results = new ContentProviderResult[numOperations]; for (int i = 0; i < numOperations; i++) { results[i] = operations.get(i).apply(this, results, i); } db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); } }
Example #4
Source File: FDroidProvider.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
@NonNull @Override public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { ContentProviderResult[] result = null; applyingBatch = true; final SQLiteDatabase db = db(); db.beginTransaction(); try { result = super.applyBatch(operations); db.setTransactionSuccessful(); } finally { db.endTransaction(); applyingBatch = false; } return result; }
Example #5
Source File: SQLiteProvider.java From android-atleap with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { ContentProviderResult[] result = null; SQLiteDatabase db = this.getDatabaseHelper().getWritableDatabase(); db.beginTransaction(); try { result = super.applyBatch(operations); db.setTransactionSuccessful(); } finally { db.endTransaction(); } return result; }
Example #6
Source File: TransactionHelper.java From CPOrm with MIT License | 6 votes |
public static void saveInTransaction(Context context, List<? extends CPDefaultRecord> records) throws RemoteException, OperationApplicationException { List<ContentProviderOperation> operations = prepareTransaction(context, records); ContentProviderResult[] contentProviderResults = CPOrm.applyPreparedOperations(operations); Map<Class, Long> referenceIds = new HashMap<>(); for (int i = 0; i < contentProviderResults.length; i++) { ContentProviderResult result = contentProviderResults[i]; CPDefaultRecord source = records.get(i); referenceIds.remove(source.getClass()); if(result.uri != null && source.getId() == null && ContentUris.parseId(result.uri) != -1){ source.setId(ContentUris.parseId(result.uri)); referenceIds.put(source.getClass(), source.getId()); } try { applyReferenceResults(source.getClass(), source, referenceIds); } catch (IllegalAccessException e) { CPOrmLog.e("Failed to apply back reference id's for uri " + result.uri); } } }
Example #7
Source File: ContactProvider.java From RememBirthday with GNU General Public License v3.0 | 6 votes |
@Override protected Exception doInBackground(Void... voids) { try { ArrayList<ContentProviderOperation> ops = new ArrayList<>(); ContentProviderOperation.Builder contentBuilder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) .withSelection(ContactsContract.Data._ID + " =? AND " + ContactsContract.Data.MIMETYPE + " =? AND " + ContactsContract.CommonDataKinds.Event.START_DATE + " =? AND " + ContactsContract.CommonDataKinds.Event.TYPE + " =?" , new String[]{String.valueOf(dataId), ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE, oldBirthday.toBackupString(), String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)}) .withValue(ContactsContract.CommonDataKinds.Event.START_DATE, birthday.toBackupString()); Log.d(getClass().getSimpleName(), "Update birthday " + oldBirthday + " to " + birthday); ops.add(contentBuilder.build()); ContentProviderResult[] results = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); if(results[0].count == 0) return new Exception("Unable to update birthday"); } catch(Exception e) { return e; } return null; }
Example #8
Source File: ContactProvider.java From RememBirthday with GNU General Public License v3.0 | 6 votes |
@Override protected Exception doInBackground(Void... params) { try { ArrayList<ContentProviderOperation> ops = new ArrayList<>(); ContentProviderOperation.Builder contentBuilder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId) .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE) .withValue(ContactsContract.CommonDataKinds.Event.START_DATE, birthday.toBackupString()) .withValue(ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY); Log.d(getClass().getSimpleName(), "Add birthday " + birthday); ops.add(contentBuilder.build()); ContentProviderResult[] results = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); if(results[0] == null) throw new Exception("Unable to add new birthday"); } catch(Exception e) { return e; } return null; }
Example #9
Source File: EventLoader.java From RememBirthday with GNU General Public License v3.0 | 6 votes |
public synchronized static void deleteEventsFromContact(Context context, Contact contact) { ArrayList<ContentProviderOperation> operations = new ArrayList<>(); try { for (CalendarEvent event : getEventsSavedForEachYear(context, contact)) { operations.add(ReminderProvider.deleteAll(context, event.getId())); operations.add(EventProvider.delete(event)); } ContentProviderResult[] contentProviderResults = context.getContentResolver().applyBatch(CalendarContract.AUTHORITY, operations); for(ContentProviderResult contentProviderResult : contentProviderResults) { Log.d(TAG, contentProviderResult.toString()); if (contentProviderResult.uri != null) Log.d(TAG, contentProviderResult.uri.toString()); } } catch (RemoteException |OperationApplicationException |EventException e) { Log.e(TAG, "Unable to deleteById events : " + e.getMessage()); } }
Example #10
Source File: EventLoader.java From RememBirthday with GNU General Public License v3.0 | 6 votes |
public synchronized static void updateEvent(Context context, Contact contact, DateUnknownYear newBirthday) throws EventException { // TODO UNIFORMISE for (CalendarEvent event : getEventsSavedOrCreateNewsForEachYear(context, contact)) { // Construct each anniversary of new birthday int year = new DateTime(event.getDate()).getYear(); Date newBirthdayDate = DateUnknownYear.getDateWithYear(newBirthday.getDate(), year); event.setDateStart(newBirthdayDate); event.setAllDay(true); ArrayList<ContentProviderOperation> operations = new ArrayList<>(); ContentProviderOperation contentProviderOperation = EventProvider.update(event); operations.add(contentProviderOperation); try { ContentProviderResult[] contentProviderResults = context.getContentResolver().applyBatch(CalendarContract.AUTHORITY, operations); for(ContentProviderResult contentProviderResult : contentProviderResults) { if (contentProviderResult.count != 0) Log.d(TAG, "Update event : " + event.toString()); } } catch (RemoteException|OperationApplicationException e) { Log.e(TAG, "Unable to update event : " + e.getMessage()); } } }
Example #11
Source File: ItemsProvider.java From make-your-app-material with Apache License 2.0 | 6 votes |
/** * Apply the given set of {@link ContentProviderOperation}, executing inside * a {@link SQLiteDatabase} transaction. All changes will be rolled back if * any single one fails. */ @NonNull public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { final int numOperations = operations.size(); final ContentProviderResult[] results = new ContentProviderResult[numOperations]; for (int i = 0; i < numOperations; i++) { results[i] = operations.get(i).apply(this, results, i); } db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); } }
Example #12
Source File: BatchOperation.java From tindroid with Apache License 2.0 | 6 votes |
@SuppressWarnings("UnusedReturnValue") List<Uri> execute() { List<Uri> resultUris = new ArrayList<>(); if (mOperations.size() == 0) { return resultUris; } // Apply the mOperations to the content provider try { ContentProviderResult[] results = mResolver.applyBatch(ContactsContract.AUTHORITY, mOperations); if (results.length > 0) { for (ContentProviderResult result : results) { resultUris.add(result.uri); } } } catch (final OperationApplicationException | RemoteException e) { Log.e(TAG, "storing contact data failed", e); } mOperations.clear(); return resultUris; }
Example #13
Source File: DevicesProvider.java From device-database with Apache License 2.0 | 6 votes |
@Override public @NonNull ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { final SQLiteDatabase db = helper.getWritableDatabase(); db.beginTransaction(); try { final ContentProviderResult[] results = super.applyBatch(operations); db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); } }
Example #14
Source File: EspContactTool.java From espresso-macchiato with MIT License | 6 votes |
public static Uri add(ContactSpec spec) { // original code http://stackoverflow.com/questions/4744187/how-to-add-new-contacts-in-android // good blog http://androiddevelopement.blogspot.de/2011/07/insert-update-delete-view-contacts-in.html ArrayList<ContentProviderOperation> ops = new ArrayList<>(); addContactBase(ops); addContactDisplayName(spec, ops); addContactAddress(spec, ops); try { ContentProviderResult[] results = InstrumentationRegistry.getTargetContext().getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); return results[0].uri; } catch (RemoteException | OperationApplicationException e) { throw new IllegalStateException("Could not add contact", e); } }
Example #15
Source File: FileContentProvider.java From Cirrus_depricated with GNU General Public License v2.0 | 6 votes |
@Override public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { Log_OC.d("FileContentProvider", "applying batch in provider " + this + " (temporary: " + isTemporary() + ")" ); ContentProviderResult[] results = new ContentProviderResult[operations.size()]; int i=0; SQLiteDatabase db = mDbHelper.getWritableDatabase(); db.beginTransaction(); // it's supposed that transactions can be nested try { for (ContentProviderOperation operation : operations) { results[i] = operation.apply(this, results, i); i++; } db.setTransactionSuccessful(); } finally { db.endTransaction(); } Log_OC.d("FileContentProvider", "applied batch in provider " + this); return results; }
Example #16
Source File: DataProvider.java From narrate-android with Apache License 2.0 | 6 votes |
/** * Apply the given set of {@link ContentProviderOperation}, executing inside * a {@link SQLiteDatabase} transaction. All changes will be rolled back if * any single one fails. */ @Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase(); db.beginTransaction(); try { final int numOperations = operations.size(); final ContentProviderResult[] results = new ContentProviderResult[numOperations]; for (int i = 0; i < numOperations; i++) { results[i] = operations.get(i).apply(this, results, i); } db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); } }
Example #17
Source File: RemoteContentProvider.java From VirtualAPK with Apache License 2.0 | 6 votes |
@NonNull @Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { try { Field uriField = ContentProviderOperation.class.getDeclaredField("mUri"); uriField.setAccessible(true); for (ContentProviderOperation operation : operations) { Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(KEY_URI)); uriField.set(operation, pluginUri); } } catch (Exception e) { return new ContentProviderResult[0]; } if (operations.size() > 0) { ContentProvider provider = getContentProvider(operations.get(0).getUri()); if (provider != null) { return provider.applyBatch(operations); } } return new ContentProviderResult[0]; }
Example #18
Source File: ContactsSaver.java From AndroidContacts with MIT License | 6 votes |
private ContentProviderResult[] createContacts(List<ContactData> contacts) { ContentProviderResult[] results = null; ArrayList<ContentProviderOperation> op_list = new ArrayList<>(); for (int i = 0; i < contacts.size(); i++) { ContactData contactData = contacts.get(i); op_list.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, contactData.getAccountType()) .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, contactData.getAccountName()) .withValue(ContactsContract.RawContacts.STARRED, contactData.isFavorite() ? 1 : 0) .build()); } try { results = mResolver.applyBatch(ContactsContract.AUTHORITY, op_list); } catch (Exception ignored) { } return results; }
Example #19
Source File: ActivityItemsProvider.java From GitJourney with Apache License 2.0 | 6 votes |
/** * Apply the given set of {@link ContentProviderOperation}, executing inside * a {@link SQLiteDatabase} transaction. All changes will be rolled back if * any single one fails. */ public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { final SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { final int numOperations = operations.size(); final ContentProviderResult[] results = new ContentProviderResult[numOperations]; for (int i = 0; i < numOperations; i++) { results[i] = operations.get(i).apply(this, results, i); } db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); } }
Example #20
Source File: ContactsSaver.java From AndroidContacts with MIT License | 5 votes |
public int[] insertContacts(List<ContactData> contactDataList) { ArrayList<ContentValues> cvList = new ArrayList<>(100); ContentProviderResult[] results = createContacts(contactDataList); int[] ids = new int[results.length]; for (int i = 0; i < results.length; i++) { int id = Integer.parseInt(results[i].uri.getLastPathSegment()); generateInsertOperations(cvList, contactDataList.get(i), id); ids[i] = id; } mResolver.bulkInsert(ContactsContract.Data.CONTENT_URI, cvList.toArray(new ContentValues[cvList.size()])); return ids; }
Example #21
Source File: RequestExecutor.java From arca-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public BatchResult execute(final Batch request) { final ContentResolver resolver = getContentResolver(); try { final ContentProviderResult[] results = resolver.applyBatch(request.getAuthority(), request.getOperations()); return new BatchResult(results); } catch (final Exception e) { return new BatchResult(new Error(0, e.getMessage())); } }
Example #22
Source File: DatabaseProvider.java From arca-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public ContentProviderResult[] applyBatch(final ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { final SQLiteDatabase database = getDatabase(); database.beginTransaction(); try { final ContentProviderResult[] results = super.applyBatch(operations); database.setTransactionSuccessful(); return results; } finally { database.endTransaction(); } }
Example #23
Source File: LauncherProvider.java From LB-Launcher with Apache License 2.0 | 5 votes |
@Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { ContentProviderResult[] result = super.applyBatch(operations); db.setTransactionSuccessful(); return result; } finally { db.endTransaction(); } }
Example #24
Source File: APEZProvider.java From react-native-video with MIT License | 5 votes |
@Override public ContentProviderResult[] applyBatch( ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { initIfNecessary(); return super.applyBatch(operations); }
Example #25
Source File: CPOrmContentProvider.java From CPOrm with MIT License | 5 votes |
@NonNull @Override public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { if (debugEnabled) { CPOrmLog.d("********* Apply Batch **********"); CPOrmLog.d("Operations Count: " + operations.size()); } isBatchOperation.set(true); changedUri.set(new LinkedHashSet<Uri>()); boolean success = false; ContentProviderResult[] contentProviderResults = null; SQLiteDatabase db = database.getWritableDatabase(); try { db.beginTransactionNonExclusive(); contentProviderResults = super.applyBatch(operations); db.setTransactionSuccessful(); success = true; return contentProviderResults; } finally { db.endTransaction(); if(success && changedUri.get() != null) { for (Uri uri : changedUri.get()) { if (uri != null) { TableDetails tableDetails = uriMatcherHelper.getTableDetails(uri); notifyChanges(uri, tableDetails); } } } isBatchOperation.set(false); changedUri.remove(); } }
Example #26
Source File: APEZProvider.java From Alite with GNU General Public License v3.0 | 5 votes |
@Override public ContentProviderResult[] applyBatch( ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { initIfNecessary(); return super.applyBatch(operations); }
Example #27
Source File: LauncherProvider.java From TurboLauncher with Apache License 2.0 | 5 votes |
@Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { ContentProviderResult[] result = super.applyBatch(operations); db.setTransactionSuccessful(); return result; } finally { db.endTransaction(); } }
Example #28
Source File: GutenbergProvider.java From attendee-checkin with Apache License 2.0 | 5 votes |
@Override public ContentProviderResult[] applyBatch( @NonNull ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { SQLiteDatabase db = mHelper.getWritableDatabase(); db.beginTransaction(); try { ContentProviderResult[] result = super.applyBatch(operations); db.setTransactionSuccessful(); return result; } finally { db.endTransaction(); } }
Example #29
Source File: APODContentProvider.java From stetho with MIT License | 5 votes |
@Override public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException { SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try { ContentProviderResult[] results = super.applyBatch(operations); db.setTransactionSuccessful(); return results; } finally { db.endTransaction(); notifyChange(); } }
Example #30
Source File: Logger.java From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates new logger session. Must be created before appending log entries. * If the nRF Logger application is not installed the method will return <code>null</code>. * * @param context the context (activity, service or application). * @param profile application profile which will be concatenated to the application name. * @param key the session key, which is used to group sessions. * @param name the human readable session name. * @return The {@link LogSession} that can be used to append log entries or <code>null</code> * if nRF Logger is not installed. The <code>null</code> value can be next passed to logging methods. */ @Nullable public static LogSession newSession(@NonNull final Context context, @Nullable final String profile, @NonNull final String key, @Nullable final String name) { final ArrayList<ContentProviderOperation> ops = new ArrayList<>(); ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(LogContract.Application.CONTENT_URI); final String appName = context.getApplicationInfo() .loadLabel(context.getPackageManager()).toString(); if (profile != null) builder.withValue(LogContract.Application.APPLICATION, appName + " " + profile); else builder.withValue(LogContract.Application.APPLICATION, appName); ops.add(builder.build()); final Uri uri = LogContract.Session.CONTENT_URI.buildUpon() .appendEncodedPath(LogContract.Session.KEY_CONTENT_DIRECTORY) .appendEncodedPath(key) .build(); builder = ContentProviderOperation.newInsert(uri) .withValueBackReference(LogContract.Session.APPLICATION_ID, 0) .withValue(LogContract.Session.NAME, name); ops.add(builder.build()); try { final ContentProviderResult[] results = context.getContentResolver() .applyBatch(LogContract.AUTHORITY, ops); final Uri sessionUri = results[1].uri; return new LogSession(context, sessionUri); } catch (final Exception e) { // the nRF Logger application is not installed, do nothing return null; } }