android.content.ContentUris Java Examples
The following examples show how to use
android.content.ContentUris.
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: ImageUtil.java From XposedNavigationBar with GNU General Public License v3.0 | 10 votes |
/** * @param data * @return 图片路径 */ public static String handleImageOnKitKat(Intent data) { String imagePath = ""; Log.i(TAG, "handleImageOnKitKat: "); Uri uri = data.getData(); if (DocumentsContract.isDocumentUri(MyApplication.getContext(), uri)) { //如果是document类型的uri,则通过document id处理 String docId = DocumentsContract.getDocumentId(uri); if ("com.android.providers.media.documents".equals(uri.getAuthority())) { String id = docId.split(":")[1];//解析出数字格式的ID String selection = MediaStore.Images.Media._ID + "=" + id; imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection); } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId)); imagePath = getImagePath(contentUri, null); } } else if ("content".equalsIgnoreCase(uri.getScheme())) { //如果是content类型的uri,则使用普通的方式处理 imagePath = getImagePath(uri, null); } else if ("file".equalsIgnoreCase(uri.getScheme())) { //如果是file类型的uri,直接获取图片路径即可 imagePath = uri.getPath(); } return imagePath; }
Example #2
Source File: BufferProvider.java From TimberLorry with Apache License 2.0 | 6 votes |
private String buildSelection(Uri uri, String selection) { long id; String additionalSelection = null; switch (MATCHER.match(uri)) { case TYPE_LOG_BUFFER: id = ContentUris.parseId(uri); additionalSelection = BufferScheme._ID + " = " + id; break; case TYPE_LOG_BUFFERS: // do nothing break; default: throw new IllegalArgumentException("unknown uri: " + uri); } if (additionalSelection == null) { return selection; } if (selection == null) { return additionalSelection; } return additionalSelection + " AND " + selection; }
Example #3
Source File: ContactsUtils5.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
@Override public ContactInfo getContactInfo(Context context, Cursor cursor) { ContactInfo ci = new ContactInfo(); // Get values ci.displayName = cursor.getString(cursor.getColumnIndex(Contacts.DISPLAY_NAME)); ci.contactId = cursor.getLong(cursor.getColumnIndex(Contacts._ID)); ci.callerInfo.contactContentUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, ci.contactId); ci.callerInfo.photoId = cursor.getLong(cursor.getColumnIndex(Contacts.PHOTO_ID)); int photoUriColIndex = cursor.getColumnIndex(Contacts.PHOTO_ID); ci.status = cursor.getString(cursor.getColumnIndex(Contacts.CONTACT_STATUS)); ci.presence = cursor.getInt(cursor.getColumnIndex(Contacts.CONTACT_PRESENCE)); if (photoUriColIndex >= 0) { String photoUri = cursor.getString(photoUriColIndex); if (!TextUtils.isEmpty(photoUri)) { ci.callerInfo.photoUri = Uri.parse(photoUri); } } ci.hasPresence = !TextUtils.isEmpty(ci.status); return ci; }
Example #4
Source File: FilePathHelper.java From qcloud-sdk-android-samples with MIT License | 6 votes |
@RequiresApi(api = Build.VERSION_CODES.KITKAT) private static String getKitKatPathFromMediaUri(Context context, Uri uri) { String imagePath = ""; if (DocumentsContract.isDocumentUri(context, uri)) { String docId = DocumentsContract.getDocumentId(uri); if ("com.android.providers.media.documents".equals(uri.getAuthority())) { //Log.d(TAG, uri.toString()); String id = docId.split(":")[1]; String selection = MediaStore.Images.Media._ID + "=" + id; imagePath = getImagePathFromMediaUri(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection); } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { //Log.d(TAG, uri.toString()); Uri contentUri = ContentUris.withAppendedId( Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId)); imagePath = getImagePathFromMediaUri(context, contentUri, null); } } else if ("content".equalsIgnoreCase(uri.getScheme())) { //Log.d(TAG, "content: " + uri.toString()); imagePath = getImagePathFromMediaUri(context, uri, null); } return imagePath; }
Example #5
Source File: AddVoicemailTester.java From PermissionAgent with Apache License 2.0 | 6 votes |
@Override public boolean test() throws Throwable { try { Uri mBaseUri = VoicemailContract.Voicemails.CONTENT_URI; ContentValues contentValues = new ContentValues(); contentValues.put(VoicemailContract.Voicemails.DATE, System.currentTimeMillis()); contentValues.put(VoicemailContract.Voicemails.NUMBER, "1"); contentValues.put(VoicemailContract.Voicemails.DURATION, 1); contentValues.put(VoicemailContract.Voicemails.SOURCE_PACKAGE, "permission"); contentValues.put(VoicemailContract.Voicemails.SOURCE_DATA, "permission"); contentValues.put(VoicemailContract.Voicemails.IS_READ, 0); Uri newVoicemailUri = mResolver.insert(mBaseUri, contentValues); long id = ContentUris.parseId(newVoicemailUri); int count = mResolver.delete(mBaseUri, VoicemailContract.Voicemails._ID + "=?", new String[] {Long.toString(id)}); return count > 0; } catch (Exception e) { String message = e.getMessage(); if (!TextUtils.isEmpty(message)) { message = message.toLowerCase(); return !message.contains("add_voicemail"); } return false; } }
Example #6
Source File: PersistentBlobProvider.java From bcm-android with GNU General Public License v3.0 | 6 votes |
public boolean delete(@NonNull Uri uri) { switch (MATCHER.match(uri)) { case MATCH_OLD: case MATCH_NEW: long id = ContentUris.parseId(uri); cache.remove(id); return getFile(ContentUris.parseId(uri)).delete(); default: break; } if (isExternalBlobUri(context, uri)) { String fileAuthority = BuildConfig.BCM_APPLICATION_ID + ".fileprovider"; if (fileAuthority.equals(uri.getAuthority())) { return context.getContentResolver().delete(uri, null, null) > 0; }else { return new File(uri.getPath()).delete(); } } return false; }
Example #7
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 #8
Source File: Filter.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
public static Filter getFilterFromDbId(Context ctxt, long filterId, String[] projection) { Filter filter = new Filter(); if(filterId >= 0) { Cursor c = ctxt.getContentResolver().query(ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, filterId), projection, null, null, null); if(c != null) { try { if(c.getCount() > 0) { c.moveToFirst(); filter = new Filter(c); } }catch(Exception e) { Log.e(THIS_FILE, "Something went wrong while retrieving the account", e); } finally { c.close(); } } } return filter; }
Example #9
Source File: MySearchActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 6 votes |
@Override public void onBindViewHolder(@NonNull final ViewHolder holder, int position) { if (mValues != null) { // Move the Cursor to the correct position, extract the // search result values, and assign them to the UI for // each search result. mValues.moveToPosition(position); holder.mNameView.setText(mValues.getString(mHoardNameIndex)); holder.mAmountView.setText(mValues.getString(mHoardAmountIndex)); // Create a Uri that points to this search result item. int rowId = mValues.getInt(mHoardIdIndex); final Uri rowAddress = ContentUris.withAppendedId(MyHoardContentProvider.CONTENT_URI, rowId); // Return the Uri to this search result item if clicked. holder.mView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mClickListener.onListItemClick(rowAddress); } }); } }
Example #10
Source File: GanHuoContentProvider.java From base-module with Apache License 2.0 | 6 votes |
@Nullable @Override public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) { Uri returnUri = null; SQLiteDatabase db = mDatabaseHelper.getWritableDatabase(); String tableName = DatabaseManager.matchUri(uri); long rowId = -1; try { db.beginTransaction(); rowId = db.replace(tableName, null, values); return rowId > 0 ? ContentUris.withAppendedId(uri, rowId) : ContentUris.withAppendedId(uri, -1); } catch (SQLException e) { Log.e(TAG, "insert " + tableName + " error: " + e); e.printStackTrace(); } finally { db.endTransaction(); } return returnUri; }
Example #11
Source File: ConversationListItem.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
private String getGroupCount(ContentResolver resolver, long groupId) { String[] projection = { Imps.GroupMembers.NICKNAME }; Uri uri = ContentUris.withAppendedId(Imps.GroupMembers.CONTENT_URI, groupId); Cursor c = resolver.query(uri, projection, null, null, null); StringBuilder buf = new StringBuilder(); if (c != null) { buf.append(" ("); buf.append(c.getCount()); buf.append(")"); c.close(); } return buf.toString(); }
Example #12
Source File: Contacts.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Creates a new contacts and adds it to the "My Contacts" group. * * @param resolver the ContentResolver to use * @param values the values to use when creating the contact * @return the URI of the contact, or null if the operation fails * @deprecated see {@link android.provider.ContactsContract} */ @Deprecated public static Uri createPersonInMyContactsGroup(ContentResolver resolver, ContentValues values) { Uri contactUri = resolver.insert(People.CONTENT_URI, values); if (contactUri == null) { Log.e(TAG, "Failed to create the contact"); return null; } if (addToMyContactsGroup(resolver, ContentUris.parseId(contactUri)) == null) { resolver.delete(contactUri, null, null); return null; } return contactUri; }
Example #13
Source File: MainActivity.java From GenerateQRCode with Apache License 2.0 | 6 votes |
/** * 4.4以后 * * @param data */ @SuppressLint("NewApi") private void handleImageOnKitKat(Intent data) { String imagePath = null; Uri uri = data.getData(); Log.d("TAG", "handleImageOnKitKat: uri is " + uri); if (DocumentsContract.isDocumentUri(this, uri)) { // 如果是document类型的Uri,则通过document id处理 String docId = DocumentsContract.getDocumentId(uri); if ("com.android.providers.media.documents".equals(uri.getAuthority())) { String id = docId.split(":")[1]; // 解析出数字格式的id String selection = MediaStore.Images.Media._ID + "=" + id; imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection); } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId)); imagePath = getImagePath(contentUri, null); } } else if ("content".equalsIgnoreCase(uri.getScheme())) { // 如果是content类型的Uri,则使用普通方式处理 imagePath = getImagePath(uri, null); } else if ("file".equalsIgnoreCase(uri.getScheme())) { // 如果是file类型的Uri,直接获取图片路径即可 imagePath = uri.getPath(); } displayImage(imagePath); // 根据图片路径显示图片 }
Example #14
Source File: DataProvider.java From trekarta with GNU General Public License v3.0 | 6 votes |
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { logger.debug("insert({})", uri); if (uriMatcher.match(uri) != MAP_OBJECTS) { throw new IllegalArgumentException("Unknown URI " + uri); } if (values == null) { throw new IllegalArgumentException("Values can not be null"); } MapObject mo = new MapObject(0, 0); populateFields(mo, values); long id = MapTrek.addMapObject(mo); Uri objectUri = ContentUris.withAppendedId(DataContract.MAPOBJECTS_URI, id); Context context = getContext(); if (context != null) context.getContentResolver().notifyChange(objectUri, null); return objectUri; }
Example #15
Source File: AccountFiltersListFragment.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
@Override public boolean onContextItemSelected(android.view.MenuItem item) { final long filterId = filterIdFromContextMenuInfo(item.getMenuInfo()); if (filterId == -1) { // For some reason the requested item isn't available, do nothing return super.onContextItemSelected(item); } switch (item.getItemId()) { case MENU_ITEM_DELETE: { getActivity().getContentResolver().delete(ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, filterId), null, null); return true; } case MENU_ITEM_MODIFY : { showDetails(filterId); return true; } } return super.onContextItemSelected(item); }
Example #16
Source File: DBAccessUtils.java From AudioAnchor with GNU General Public License v3.0 | 6 votes |
static void deleteBookmarksForTrack(Context context, long trackId) { // Get all bookmarks associated with the trackId String[] columns = new String[]{AnchorContract.BookmarkEntry._ID, AnchorContract.BookmarkEntry.COLUMN_AUDIO_FILE}; String sel = AnchorContract.BookmarkEntry.COLUMN_AUDIO_FILE + "=?"; String[] selArgs = {Long.toString(trackId)}; Cursor c = context.getContentResolver().query(AnchorContract.BookmarkEntry.CONTENT_URI, columns, sel, selArgs, null, null); // Bail early if the cursor is null if (c == null) { return; } else if (c.getCount() < 1) { c.close(); return; } while (c.moveToNext()) { // Delete bookmarks associated with the track from the database int bookmarkId = c.getInt(c.getColumnIndex(AnchorContract.BookmarkEntry._ID)); Uri deleteUri = ContentUris.withAppendedId(AnchorContract.BookmarkEntry.CONTENT_URI, bookmarkId); context.getContentResolver().delete(deleteUri, null, null); } c.close(); }
Example #17
Source File: TestProvider.java From Popular-Movies-App with Apache License 2.0 | 6 votes |
public void testDeleteMovieById() { ContentValues testValues = TestUtilities.createTestMovieValues(); Uri movieUri = mContext.getContentResolver().insert(MoviesContract.MovieEntry.CONTENT_URI, testValues); assertTrue(movieUri != null); long id = ContentUris.parseId(movieUri); assertTrue(id != -1); assertEquals(MoviesContract.MovieEntry.buildMovieUri(id), movieUri); TestUtilities.TestContentObserver moviesObserver = TestUtilities.getTestContentObserver(); mContext.getContentResolver().registerContentObserver(MoviesContract.MovieEntry.CONTENT_URI, true, moviesObserver); TestUtilities.TestContentObserver movieByIdObserver = TestUtilities.getTestContentObserver(); mContext.getContentResolver().registerContentObserver(movieUri, true, movieByIdObserver); mContext.getContentResolver().delete( MoviesContract.MovieEntry.buildMovieUri(id), null, null ); moviesObserver.waitForNotificationOrFail(); movieByIdObserver.waitForNotificationOrFail(); mContext.getContentResolver().unregisterContentObserver(moviesObserver); mContext.getContentResolver().unregisterContentObserver(movieByIdObserver); }
Example #18
Source File: Calendar.java From intra42 with Apache License 2.0 | 6 votes |
private static void removeEventFromCalendar(Context context, int event) { Uri eventsUri = Uri.parse("content://com.android.calendar/events"); ContentResolver resolver = context.getContentResolver(); String selection = CalendarContract.Events.CUSTOM_APP_URI + " = ?"; String[] selectionArgs = {getEventUri(event)}; Cursor cursor = resolver.query(eventsUri, new String[]{"_id"}, selection, selectionArgs, null); while (cursor.moveToNext()) { long eventId = cursor.getLong(cursor.getColumnIndex("_id")); resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null); } cursor.close(); }
Example #19
Source File: HobbitProviderImplHashMap.java From mobilecloud-15 with Apache License 2.0 | 6 votes |
/** * Method called to handle query requests from client * applications. This plays the role of the "concrete hook * method" in the Template Method pattern. */ @Override public Cursor queryCharacter(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final MatrixCursor cursor = new MatrixCursor(CharacterContract.CharacterEntry.sColumnsToDisplay); // Just return a single item from the database. long requestId = ContentUris.parseId(uri); synchronized (this) { CharacterRecord cr = mCharacterMap.get(requestId); if (cr != null) { buildCursorConditionally(cursor, cr, selection, selectionArgs); } } return cursor; }
Example #20
Source File: FavAdapter.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
@Override public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { int itemId = item.getItemId(); if(itemId == R.id.set_group) { showDialogForGroupSelection(context, profileId, groupName); return true; }else if(itemId == R.id.share_presence) { ContentValues cv = new ContentValues(); cv.put(SipProfile.FIELD_PUBLISH_ENABLED, publishEnabled ? 0 : 1); context.getContentResolver().update(ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, profileId), cv, null, null); return true; }else if(itemId == R.id.set_sip_data) { showDialogForSipData(context, profileId, groupName, domain); return true; } return false; }
Example #21
Source File: SipProfile.java From CSipSimple with GNU General Public License v3.0 | 6 votes |
/** * Helper method to retrieve a SipProfile object from its account database * id.<br/> * You have to specify the projection you want to use for to retrieve infos.<br/> * As consequence the wrapper SipProfile object you'll get may be * incomplete. So take care if you try to reinject it by updating to not * override existing values of the database that you don't get here. * * @param ctxt Your application context. Mainly useful to get the content provider for the request. * @param accountId The sip profile {@link #FIELD_ID} you want to retrieve. * @param projection The list of fields you want to retrieve. Must be in FIELD_* of this class.<br/> * Reducing your requested fields to minimum will improve speed of the request. * @return A wrapper SipProfile object on the request you done. If not found an invalid account with an {@link #id} equals to {@link #INVALID_ID} */ public static SipProfile getProfileFromDbId(Context ctxt, long accountId, String[] projection) { SipProfile account = new SipProfile(); if (accountId != INVALID_ID) { Cursor c = ctxt.getContentResolver().query( ContentUris.withAppendedId(ACCOUNT_ID_URI_BASE, accountId), projection, null, null, null); if (c != null) { try { if (c.getCount() > 0) { c.moveToFirst(); account = new SipProfile(c); } } catch (Exception e) { Log.e(THIS_FILE, "Something went wrong while retrieving the account", e); } finally { c.close(); } } } return account; }
Example #22
Source File: ConversationDetailActivity.java From Zom-Android-XMPP with GNU General Public License v3.0 | 6 votes |
@Override protected void onResume() { super.onResume(); Intent intent = getIntent(); processIntent(intent); mConvoView.setSelected(true); IntentFilter regFilter = new IntentFilter(); regFilter .addAction(Intent.ACTION_SCREEN_OFF); regFilter .addAction(Intent.ACTION_SCREEN_ON); registerReceiver(receiver, regFilter); // Set last read date now! if (mChatId != -1) { ContentValues values = new ContentValues(1); values.put(Imps.Chats.LAST_READ_DATE, System.currentTimeMillis()); getContentResolver().update(ContentUris.withAppendedId(Imps.Chats.CONTENT_URI, mChatId), values, null, null); } }
Example #23
Source File: MongoBrowserProvider.java From MongoExplorer with MIT License | 6 votes |
@Override public Uri insert(Uri uri, ContentValues values) { String table; Uri newUri; switch (URI_MATCHER.match(uri)) { case CONNECTION_ALL: table = TABLE_NAME_CONNECTIONS; newUri = CONNECTION_URI; break; case QUERY_ALL: table = TABLE_NAME_QUERIES; newUri = QUERY_URI; break; default: throw new IllegalArgumentException("Unknown URI " + uri); } long id = mDatabase.insert(table, null, values); newUri = ContentUris.withAppendedId(newUri, id); getContext().getContentResolver().notifyChange(newUri, null); Log.d(LOG_TAG, "Insert " + id); return newUri; }
Example #24
Source File: BitmapHelper.java From libcommon with Apache License 2.0 | 5 votes |
/** * 画像の回転角度を取得 * @param cr * @param id * @return 0, 90, 180, 270 */ public static int getOrientation( @NonNull final ContentResolver cr, final long id) { return getOrientation(cr, ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)); }
Example #25
Source File: TicketsAdapter.java From sms-ticket with Apache License 2.0 | 5 votes |
/** * Tries to delete ticket either from swipe-to-dismiss or button. * * @return Pair of ticket id and previous status or null if it wasn't deleted. */ public Pair<Long, Integer> archiveTicket(int position) { Cursor cursor = getCursor(); if (cursor == null || cursor.isClosed()) { return null; } cursor.moveToPosition(position); long id; try { id = cursor.getLong(iId); } catch (CursorIndexOutOfBoundsException e) { return null; } final Time validTo = FormatUtil.timeFrom3339(cursor.getString(iValidTo)); int status = getValidityStatus(cursor.getInt(iStatus), validTo); if (status == Tickets.STATUS_EXPIRED) { ContentValues values = new ContentValues(); values.put(TicketProvider.Tickets.STATUS, TicketProvider.Tickets.STATUS_DELETED); c.getContentResolver().update(ContentUris.withAppendedId(TicketProvider.Tickets.CONTENT_URI, id), values, null, null); // I had to call this deprecated method, because it needs to run synchronously. In asynchronous case, previous tickets blinks during swipe to dismiss. //noinspection deprecation getCursor().requery(); return new Pair<Long, Integer>(id, status); } else { return null; } }
Example #26
Source File: MediaStoreUtil.java From APlayer with GNU General Public License v3.0 | 5 votes |
private static void insertAlbumArt(@NonNull Context context, int albumId, String path) { ContentResolver contentResolver = context.getContentResolver(); Uri artworkUri = Uri.parse("content://media/external/audio/albumart"); contentResolver.delete(ContentUris.withAppendedId(artworkUri, albumId), null, null); ContentValues values = new ContentValues(); values.put("album_id", albumId); values.put("_data", path); contentResolver.insert(artworkUri, values); }
Example #27
Source File: MediaSetsLoader.java From YImagePicker with Apache License 2.0 | 5 votes |
private static Uri getUri(Cursor cursor) { long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Files.FileColumns._ID)); String mimeType = cursor.getString(cursor.getColumnIndex(MIME_TYPE)); Uri contentUri; if (MimeType.isImage(mimeType)) { contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; } else if (MimeType.isVideo(mimeType)) { contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; } else { contentUri = QUERY_URI; } return ContentUris.withAppendedId(contentUri, id); }
Example #28
Source File: SignInHelper.java From zom-android-matrix with Apache License 2.0 | 5 votes |
public void activateAccount(long providerId, long accountId) { // Update the active value. We restrict to only one active // account per provider right now, so update all accounts of // this provider to inactive first and then update this // account to active. ContentValues values = new ContentValues(1); values.put(Imps.Account.ACTIVE, 0); ContentResolver cr = mContext.getContentResolver(); cr.update(Imps.Account.CONTENT_URI, values, Imps.Account.PROVIDER + "=" + providerId, null); values.put(Imps.Account.ACTIVE, 1); cr.update(ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId), values, null, null); }
Example #29
Source File: LabelProvider.java From talkback with Apache License 2.0 | 5 votes |
/** * Inserts a label in the labels database. * * @param uri The content URI for labels. * @param values The values to insert for the new label. * @return The URI of the newly inserted label, or {@code null} if the insert failed. */ @Override public Uri insert(Uri uri, ContentValues values) { if (uri == null) { LogUtils.w(TAG, NULL_URI_FORMAT_STRING); return null; } if (!UserManagerCompat.isUserUnlocked(getContext())) { return null; } switch (uriMatcher.match(uri)) { case LABELS: initializeDatabaseIfNull(); if (values == null) { return null; } if (values.containsKey(LabelsTable.KEY_ID)) { LogUtils.w(TAG, "Label ID must be assigned by the database."); return null; } long rowId = database.insert(LabelsTable.TABLE_NAME, null, values); if (rowId < 0) { LogUtils.w(TAG, "Failed to insert label."); return null; } else { return ContentUris.withAppendedId(LABELS_CONTENT_URI, rowId); } default: LogUtils.w(TAG, UNKNOWN_URI_FORMAT_STRING, uri); return null; } }
Example #30
Source File: CityManager.java From sms-ticket with Apache License 2.0 | 5 votes |
public City getCity(Context c, long id) { Cursor cursor = c.getContentResolver().query(ContentUris.withAppendedId(Cities.CONTENT_URI, id), null, null, null, null); try { if (cursor.moveToFirst()) { return getCity(cursor); } else { return null; } } finally { cursor.close(); } }