List of usage examples for android.content ContentResolver update
public final int update(@RequiresPermission.Write @NonNull Uri uri, @Nullable ContentValues values, @Nullable String where, @Nullable String[] selectionArgs)
From source file:com.smarthome.deskclock.Alarms.java
/** * A convenience method to set an alarm in the Alarms * content provider.// ww w. j a va 2 s . c om * @return Time when the alarm will fire. */ public static long setAlarm(Context context, Alarm alarm) { ContentValues values = createContentValues(alarm); ContentResolver resolver = context.getContentResolver(); resolver.update(ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarm.id), values, null, null); long timeInMillis = calculateAlarm(alarm); if (alarm.enabled) { // Disable the snooze if we just changed the snoozed alarm. This // only does work if the snoozed alarm is the same as the given // alarm. // TODO: disableSnoozeAlert should have a better name. disableSnoozeAlert(context, alarm.id); // Disable the snooze if this alarm fires before the snoozed alarm. // This works on every alarm since the user most likely intends to // have the modified alarm fire next. clearSnoozeIfNeeded(context, timeInMillis); } setNextAlert(context); // postAlarmId(context,alarm); return timeInMillis; }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
public static void updateAvatarBlob(ContentResolver resolver, Uri updateUri, byte[] data, String username) { ContentValues values = new ContentValues(3); values.put(Imps.Avatars.DATA, data); StringBuilder buf = new StringBuilder(Imps.Avatars.CONTACT); buf.append("=?"); String[] selectionArgs = new String[] { username }; resolver.update(updateUri, values, buf.toString(), selectionArgs); }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
public static boolean hasAvatarContact(ContentResolver resolver, Uri updateUri, String username) { ContentValues values = new ContentValues(3); values.put(Imps.Avatars.CONTACT, username); StringBuilder buf = new StringBuilder(Imps.Avatars.CONTACT); buf.append("=?"); String[] selectionArgs = new String[] { username }; return resolver.update(updateUri, values, buf.toString(), selectionArgs) > 0; }
From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java
/** * A convenience method to set an time schedule in the Time Schedule * content provider./*from w w w . j a v a 2 s . co m*/ * @return Time when the time schedule will fire. */ public static long setTimeSchedule(Context context, TimeSchedule timeSchedule) { ContentValues values = createContentValues(timeSchedule); ContentResolver resolver = context.getContentResolver(); resolver.update(ContentUris.withAppendedId(CONTENT_URI, timeSchedule.id), values, null, null); setNextAction(context); return calculateTimeSchedule(timeSchedule); }
From source file:com.rks.musicx.misc.utils.PlaylistHelper.java
/** * Rename Playlist// ww w.ja va2s. c o m * * @param context * @param newplaylist * @param playlist_id */ public static void renamePlaylist(Context context, String newplaylist, long playlist_id) { if (permissionManager.writeExternalStorageGranted(context)) { Uri newuri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI; ContentResolver resolver = context.getContentResolver(); ContentValues values = new ContentValues(); String where = MediaStore.Audio.Playlists._ID + " =? "; String[] whereVal = { Long.toString(playlist_id) }; values.put(MediaStore.Audio.Playlists.NAME, newplaylist); resolver.update(newuri, values, where, whereVal); } else { Log.e("PlaylistHelper", "Permission failed"); } }
From source file:edu.mit.mobile.android.locast.data.TaggableItem.java
/** * Sets the tags of a given prefix for the given item. Any existing tags using the given prefix will be deleted. * @param cr//from w w w .j a v a 2 s .com * @param item * @param tags * @param prefix */ public static void putTags(ContentResolver cr, Uri item, Collection<String> tags, String prefix) { final ContentValues cv = new ContentValues(); cv.put(Tag.PATH, TaggableItem.toListString(addPrefixToTags(prefix, tags))); cv.put(CV_TAG_PREFIX, prefix); cr.update(Uri.withAppendedPath(item, Tag.PATH), cv, null, null); }
From source file:com.nbos.phonebook.sync.platform.ContactManager.java
public static void resetDirtySharedBooks(Context ctx) { ContentResolver cr = ctx.getContentResolver(); int num = cr.delete(Constants.SHARE_BOOK_URI, BookTable.DELETED + " = 1", null); Log.i(tag, "Deleted " + num + " contacts sharing with"); ContentValues values = new ContentValues(); values = new ContentValues(); values.put(BookTable.DIRTY, "0"); num = cr.update(Constants.SHARE_BOOK_URI, values, null, null); Log.i(tag, "Updated " + num + " sharebooks to dirty = 0"); }
From source file:de.ub0r.android.smsdroid.ConversationListActivity.java
/** * Mark all messages with a given {@link Uri} as read. * /* w w w. j a v a 2 s . c om*/ * @param context * {@link Context} * @param uri * {@link Uri} * @param read * read status */ static void markRead(final Context context, final Uri uri, final int read) { Log.d(TAG, "markRead(" + uri + "," + read + ")"); if (uri == null) { return; } String[] sel = Message.SELECTION_UNREAD; if (read == 0) { sel = Message.SELECTION_READ; } final ContentResolver cr = context.getContentResolver(); final ContentValues cv = new ContentValues(); cv.put(Message.PROJECTION[Message.INDEX_READ], read); try { cr.update(uri, cv, Message.SELECTION_READ_UNREAD, sel); } catch (IllegalArgumentException e) { Log.e(TAG, "failed update", e); Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show(); } SmsReceiver.updateNewMessageNotification(context, null); }
From source file:com.example.android.ennis.barrett.popularmovies.asynchronous.TMDbSyncUtil.java
/** * Removes all data from themovies, thevideos, and thereviews tables. Does not remove data * flagged favorite but the columns istoprated, and ispopular will be set to false, "0". * @param context/*w w w .j av a 2 s. co m*/ */ public static void deletePopularAndTopRated(Context context) { ContentResolver contentResolver = context.getContentResolver(); ContentValues removePopAndTop = new ContentValues(2); removePopAndTop.put(TMDbContract.Movies.IS_POPULAR, "0"); removePopAndTop.put(TMDbContract.Movies.IS_TOP_RATED, "0"); contentResolver.update(TMDbContract.Movies.URI, removePopAndTop, TMDbContract.Movies.IS_FAVORITE + " = ?", new String[] { "1" }); contentResolver.delete(TMDbContract.Movies.URI, TMDbContract.Movies.IS_POPULAR + " = ? OR " + TMDbContract.Movies.IS_TOP_RATED + " = ?", new String[] { "1", "1" }); Cursor favoriteMovieIds = getFavoriteIds(context); int numberOfIds = favoriteMovieIds.getCount(); String[] movieIds = new String[numberOfIds]; String whereClauseVideos = ""; String whereClauseReviews = ""; for (int i = 0; i < numberOfIds; i++) { favoriteMovieIds.moveToNext(); movieIds[i] = Integer.toString( favoriteMovieIds.getInt(favoriteMovieIds.getColumnIndex(TMDbContract.Movies.MOVIE_ID))); if (i == numberOfIds - 1) { whereClauseVideos += TMDbContract.Videos.MOVIE_IDS + " != ? "; whereClauseReviews += TMDbContract.Videos.MOVIE_IDS + " != ? "; } else { whereClauseVideos += TMDbContract.Videos.MOVIE_IDS + " != ? OR "; whereClauseReviews += TMDbContract.Reviews.MOVIE_IDS + " != ? OR "; } } contentResolver.delete(TMDbContract.Videos.URI, whereClauseVideos, movieIds); contentResolver.delete(TMDbContract.Reviews.URI, whereClauseReviews, movieIds); }
From source file:info.guardianproject.otr.app.im.app.DatabaseUtils.java
/** Update the data of a plugin provider. */ private static int updateProviderRow(ContentResolver cr, long providerId, String providerFullName, String signUpUrl) {/* w w w . ja va 2 s.c o m*/ // Update the full name, signup url and category each time when the plugin change // instead of specific version change because this is called only once. // It's ok to update them even the values are not changed. // Note that we don't update the provider name because it's used as // identifier at some place and the plugin should never change it. ContentValues values = new ContentValues(3); values.put(Imps.Provider.FULLNAME, providerFullName); values.put(Imps.Provider.SIGNUP_URL, signUpUrl); values.put(Imps.Provider.CATEGORY, ImApp.IMPS_CATEGORY); Uri uri = ContentUris.withAppendedId(Imps.Provider.CONTENT_URI, providerId); return cr.update(uri, values, null, null); }