Java Code Examples for android.content.ContentProvider#insert()
The following examples show how to use
android.content.ContentProvider#insert() .
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 | 5 votes |
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { ContentProvider provider = getContentProvider(uri); if (provider != null) { Uri pluginUri = Uri.parse(uri.getQueryParameter(IntentConstant.EXTRA_TARGET_URI_KEY)); return provider.insert(pluginUri, values); } return null; }
Example 2
Source File: RemoteContentProvider.java From VirtualAPK with Apache License 2.0 | 5 votes |
@Override public Uri insert(Uri uri, ContentValues values) { ContentProvider provider = getContentProvider(uri); Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI)); if (provider != null) { return provider.insert(pluginUri, values); } return uri; }
Example 3
Source File: PluginPitProviderBase.java From springreplugin with Apache License 2.0 | 5 votes |
@Override public Uri insert(Uri uri, ContentValues values) { PluginProviderHelper.PluginUri pu = mHelper.toPluginUri(uri); if (pu == null) { return null; } ContentProvider cp = mHelper.getProvider(pu); if (cp == null) { return null; } return cp.insert(pu.transferredUri, values); }
Example 4
Source File: ProviderProxy.java From ACDD with MIT License | 5 votes |
@Override public Uri insert(Uri uri, ContentValues contentValues) { ContentProvider mContentProvider = getContentProvider(); if (mContentProvider != null) { return mContentProvider.insert(uri, contentValues); } return null; }
Example 5
Source File: ContentProviderOperation.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Applies this operation using the given provider. The backRefs array is used to resolve any * back references that were requested using * {@link Builder#withValueBackReferences(ContentValues)} and * {@link Builder#withSelectionBackReference}. * @param provider the {@link ContentProvider} on which this batch is applied * @param backRefs a {@link ContentProviderResult} array that will be consulted * to resolve any requested back references. * @param numBackRefs the number of valid results on the backRefs array. * @return a {@link ContentProviderResult} that contains either the {@link Uri} of the inserted * row if this was an insert otherwise the number of rows affected. * @throws OperationApplicationException thrown if either the insert fails or * if the number of rows affected didn't match the expected count */ public ContentProviderResult apply(ContentProvider provider, ContentProviderResult[] backRefs, int numBackRefs) throws OperationApplicationException { ContentValues values = resolveValueBackReferences(backRefs, numBackRefs); String[] selectionArgs = resolveSelectionArgsBackReferences(backRefs, numBackRefs); if (mType == TYPE_INSERT) { Uri newUri = provider.insert(mUri, values); if (newUri == null) { throw new OperationApplicationException("insert failed"); } return new ContentProviderResult(newUri); } int numRows; if (mType == TYPE_DELETE) { numRows = provider.delete(mUri, mSelection, selectionArgs); } else if (mType == TYPE_UPDATE) { numRows = provider.update(mUri, values, mSelection, selectionArgs); } else if (mType == TYPE_ASSERT) { // Assert that all rows match expected values String[] projection = null; if (values != null) { // Build projection map from expected values final ArrayList<String> projectionList = new ArrayList<String>(); for (Map.Entry<String, Object> entry : values.valueSet()) { projectionList.add(entry.getKey()); } projection = projectionList.toArray(new String[projectionList.size()]); } final Cursor cursor = provider.query(mUri, projection, mSelection, selectionArgs, null); try { numRows = cursor.getCount(); if (projection != null) { while (cursor.moveToNext()) { for (int i = 0; i < projection.length; i++) { final String cursorValue = cursor.getString(i); final String expectedValue = values.getAsString(projection[i]); if (!TextUtils.equals(cursorValue, expectedValue)) { // Throw exception when expected values don't match Log.e(TAG, this.toString()); throw new OperationApplicationException("Found value " + cursorValue + " when expected " + expectedValue + " for column " + projection[i]); } } } } } finally { cursor.close(); } } else { Log.e(TAG, this.toString()); throw new IllegalStateException("bad type, " + mType); } if (mExpectedCount != null && mExpectedCount != numRows) { Log.e(TAG, this.toString()); throw new OperationApplicationException("wrong number of rows: " + numRows); } return new ContentProviderResult(numRows); }