@Test(expected = UnsupportedOperationException.class) public void parseIdThrowsUnsupportedException() { ContentUris.parseId(Uri.parse("mailto:bar@foo.com")); }
Uri rawContactUri = contentResolver.insert(ContactsContract.RawContacts .CONTENT_URI, values); long rawContactId = ContentUris.parseId(rawContactUri); values.put(ContactsContract.Contacts.Data.MIMETYPE, ContactsContract.CommonDataKinds .StructuredName.CONTENT_ITEM_TYPE);
@Test(expected = NumberFormatException.class) public void parseIdThrowsNumberFormatException() { ContentUris.parseId(Uri.withAppendedPath(URI, "bar")); }
@Override @Nullable public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { SQLiteDatabase db = databaseHelper.getWritableDatabase(); Cursor cursor = null; switch (matcher.match(uri)) { case TRANSACTIONS: cursor = LocalCupboard.getInstance().withDatabase(db).query(HttpTransaction.class). withProjection(projection). withSelection(selection, selectionArgs). orderBy(sortOrder). getCursor(); break; case TRANSACTION: cursor = LocalCupboard.getInstance().withDatabase(db).query(HttpTransaction.class). byId(ContentUris.parseId(uri)). getCursor(); break; } if (cursor != null) { cursor.setNotificationUri(getContext().getContentResolver(), uri); } return cursor; }
long id = parseId(requestUri);
result = mProvider.insert(tableUri, values); if (result != null) { rowId = ContentUris.parseId(result); entry.mRowId = rowId;
@Override protected void onInsertComplete(final int token, final Object cookie, final Uri uri) { gameId = ContentUris.parseId(uri); } };
/** * @see android.content.ContentUris#parseId(Uri) * @return The id from a content URI or -1 if the URI has no id or is malformed. */ private static long getContentUriId(Uri uri) { try { return ContentUris.parseId(uri); } catch (UnsupportedOperationException e) { return -1; } catch (NumberFormatException e) { return -1; } }
private static int uriToNotificationId(Uri uri) { return (int)ContentUris.parseId(uri); }
@Nullable private Cursor getArchiveExistsCursor(Uri voicemailUri) { return mResolver.query(VoicemailArchiveContract.VoicemailArchive.CONTENT_URI, new String[] {VoicemailArchiveContract.VoicemailArchive._ID}, VoicemailArchiveContract.VoicemailArchive.SERVER_ID + "=" + ContentUris.parseId(voicemailUri), null, null); } }
@Nullable private Cursor getCallLogInfoCursor(Uri voicemailUri) { return mResolver.query( ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI_WITH_VOICEMAIL, ContentUris.parseId(voicemailUri)), CallLogQuery._PROJECTION, null, null, null); }
private String getSelectionWithId(String selection, Uri uri) { int match = mUriMatcher.match(uri); switch (match) { case VOICEMAIL_ARCHIVE_TABLE: return selection; case VOICEMAIL_ARCHIVE_TABLE_ID: String idStr = VoicemailArchiveContract.VoicemailArchive._ID + "=" + ContentUris.parseId(uri); return TextUtils.isEmpty(selection) ? idStr : selection + " AND " + idStr; default: throw new IllegalArgumentException("Unknown uri: " + uri); } }
@Override public Boolean doInBackground(Void... params) { Cursor cursor = mContext.getContentResolver().query(VoicemailArchive.CONTENT_URI, null, VoicemailArchive.SERVER_ID + "=" + ContentUris.parseId(mVoicemailUri) + " AND " + VoicemailArchive.ARCHIVED + "= 1", null, null); boolean archived = cursor != null && cursor.getCount() > 0; cursor.close(); return archived; }
@Override public int update(Uri uri, ContentValues contentValues, String selection, String[] selectionArgs) { final int match = sUriMatcher.match(uri); switch (match) { case PRODUCTS: return updateProduct(uri, contentValues, selection, selectionArgs); case PRODUCT_ID: selection = ProductEntry._ID + "=?"; selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) }; return updateProduct(uri, contentValues, selection, selectionArgs); default: throw new IllegalArgumentException("Update is not supported for " + uri); } }
public Uri insert(Context context, T data) { ContentResolver contentResolver = context.getContentResolver(); ContentValues values = serialize(data); Uri uri = contentResolver.insert(getContentUri(), values); long id = -1; if (uri != null) { id = ContentUris.parseId(uri); } if (id < 0) { return null; } else { return uri; } }
SqlArguments(Uri url, String where, String[] args) { if (url.getPathSegments().size() == 1) { this.table = url.getPathSegments().get(0); this.where = where; this.args = args; } else if (url.getPathSegments().size() != 2) { throw new IllegalArgumentException("Invalid URI: " + url); } else if (!TextUtils.isEmpty(where)) { throw new UnsupportedOperationException("WHERE clause not supported: " + url); } else { this.table = url.getPathSegments().get(0); this.where = "_id=" + ContentUris.parseId(url); this.args = null; } }
SqlArguments(Uri url, String where, String[] args) { if (url.getPathSegments().size() == 1) { this.table = url.getPathSegments().get(0); this.where = where; this.args = args; } else if (url.getPathSegments().size() != 2) { throw new IllegalArgumentException("Invalid URI: " + url); } else if (!TextUtils.isEmpty(where)) { throw new UnsupportedOperationException("WHERE clause not supported: " + url); } else { this.table = url.getPathSegments().get(0); this.where = "_id=" + ContentUris.parseId(url); this.args = null; } }
/** * <p>Like {@link #insert()} with the option to enable/disable change notification.</p> * @param notifyChange Whether to notify observers, default is true * @return the <b>id</b> of the record, the id property of this active record * will also be updated */ public long insert(boolean notifyChange) { AbstractValuesBuilder builder = createBuilder(); Uri uri = builder.insert(notifyChange); mId = ContentUris.parseId(uri); makeDirty(false); return mId; }
@Override public int delete(MechanoidContentProvider provider, Uri uri, String selection, String[] selectionArgs){ final SQLiteDatabase db = provider.getOpenHelper().getWritableDatabase(); if(mForUrisWithId) { long id = ContentUris.parseId(uri); int affected = SQuery.newQuery() .expr(BaseColumns._ID, SQuery.Op.EQ, id) .append(selection, selectionArgs) .delete(db, mSource); return affected; } else { return db.delete(mSource, selection, selectionArgs); } }