Java Code Examples for android.content.ContentResolver#update()
The following examples show how to use
android.content.ContentResolver#update() .
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: ContactsHelper.java From NonViewUtils with Apache License 2.0 | 8 votes |
/** * 修改联系人数据 */ public boolean update(String name, String phoneNumber) { try { //根据姓名求id,再根据id删除 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentResolver resolver = mContext.getContentResolver(); Cursor cursor = resolver.query(uri, new String[]{Data._ID}, "display_name=?", new String[]{name}, null); if (cursor.moveToFirst()) { int id = cursor.getInt(0); Uri mUri = Uri.parse("content://com.android.contacts/data");//对data表的所有数据操作 ContentResolver mResolver = mContext.getContentResolver(); ContentValues values = new ContentValues(); values.put("data1", phoneNumber); mResolver.update(mUri, values, "mimetype=? and raw_contact_id=?", new String[]{"vnd.android.cursor.item/phone_v2", id + ""}); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
Example 2
Source File: QuantumFlux.java From QuantumFlux with Apache License 2.0 | 6 votes |
public static <T> void updateColumns(T dataModelObject, String... columns) { TableDetails tableDetails = findTableDetails(dataModelObject.getClass()); ContentValues contentValues = ModelInflater.deflate(tableDetails, dataModelObject); Object columnValue = ModelInflater.deflateColumn(tableDetails, tableDetails.findPrimaryKeyColumn(), dataModelObject); Uri itemUri = UriMatcherHelper.generateItemUriBuilder(tableDetails, String.valueOf(columnValue)).build(); for (String contentColumn : tableDetails.getColumnNames()) { boolean includeColumn = false; for (String column : columns) { if (contentColumn.equals(column)) { includeColumn = true; break; } } if (!includeColumn) { contentValues.remove(contentColumn); } } ContentResolver contentResolver = mApplicationContext.getContentResolver(); contentResolver.update(itemUri, contentValues, null, null); }
Example 3
Source File: MusicUtils.java From Rey-MusicPlayer with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public static boolean deleteViaContentProvider(String fullname) { Uri uri = getFileUri(Common.getInstance(), fullname); if (uri == null) { return false; } try { ContentResolver resolver = Common.getInstance().getContentResolver(); // change type to image, otherwise nothing will be deleted ContentValues contentValues = new ContentValues(); int media_type = 1; contentValues.put("media_type", media_type); resolver.update(uri, contentValues, null, null); return resolver.delete(uri, null, null) > 0; } catch (Throwable e) { return false; } }
Example 4
Source File: EnergyWrapper.java From stynico with MIT License | 6 votes |
public int updateBrightness(int progress) { ContentValues values = new ContentValues(1); ContentResolver cr = mcontext.getContentResolver(); Uri brightnessUri = Settings.System.CONTENT_URI; int result = 0; Settings.System.putInt(cr, Settings.System.SCREEN_BRIGHTNESS, progress); values.put("screen_brightness", progress); try { result = cr.update(brightnessUri, values, null, null); } catch (Exception e) { result = 0; } return result; }
Example 5
Source File: CheckInTask.java From attendee-checkin with Apache License 2.0 | 6 votes |
@Override protected Checkin doInBackground(Void... params) { ContentResolver resolver = mContext.getContentResolver(); boolean userCheckedIn = isUserCheckedIn(resolver); if (mError == ERROR_BAD_CHECK_IN) { return null; } if (!mRevert && userCheckedIn) { mError = ERROR_ALREADY_CHECKED_IN; return null; } else if (mRevert && !userCheckedIn) { mError = ERROR_NOT_YET_CHECKED_IN; return null; } ContentValues values = new ContentValues(); if (mRevert) { values.putNull(Table.Attendee.CHECKIN); } else { values.put(Table.Attendee.CHECKIN, System.currentTimeMillis()); } values.put(Table.Attendee.CHECKIN_MODIFIED, true); int count = resolver.update(Table.ATTENDEE.getBaseUri(), values, Table.Attendee.ID + " = ?", new String[]{mAttendeeId}); return count == 0 ? null : loadCheckin(resolver); }
Example 6
Source File: EnergyWrapper.java From stynico with MIT License | 6 votes |
public void updateBacklightTime(int time) { ContentValues values = new ContentValues(1); ContentResolver cr = mcontext.getContentResolver(); Uri blTimeUri = Settings.System.CONTENT_URI; int result; //Log.v("updateBacklightTime", "num:" + time); Settings.System.putInt(cr, Settings.System.SCREEN_OFF_TIMEOUT, time); // Log.v("updateBacklightTime", "putINTOK"); values.put("screen_off_timeout", time); try { result = cr.update(blTimeUri, values, null, null); } catch (Exception e) { result = 0; } // Log.v("Result", "result is:" + result); }
Example 7
Source File: Contacts.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Set the photo for this person. data may be null * @param cr the ContentResolver to use * @param person the Uri of the person whose photo is to be updated * @param data the byte[] that represents the photo * @deprecated see {@link android.provider.ContactsContract} */ @Deprecated public static void setPhotoData(ContentResolver cr, Uri person, byte[] data) { Uri photoUri = Uri.withAppendedPath(person, Contacts.Photos.CONTENT_DIRECTORY); ContentValues values = new ContentValues(); values.put(Photos.DATA, data); cr.update(photoUri, values, null, null); }
Example 8
Source File: MediaStoreService.java From Audinaut with GNU General Public License v3.0 | 5 votes |
public void renameInMediaStore(File start, File end) { ContentResolver contentResolver = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, end.getAbsolutePath()); int n = contentResolver.update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values, MediaStore.MediaColumns.DATA + "=?", new String[]{start.getAbsolutePath()}); if (n > 0) { Log.i(TAG, "Rename media store row for " + start + " to " + end); } }
Example 9
Source File: MainActivity.java From Android-Basics-Codes with Artistic License 2.0 | 5 votes |
public void update(View v){ //��ȡContentResolver ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(); values.put("money", 13200); int i = cr.update(Uri.parse("content://cn.itcast.person"), values, "name = ?", new String[]{"�ź�"}); System.out.println(i); }
Example 10
Source File: LauncherModel.java From Trebuchet with GNU General Public License v3.0 | 5 votes |
static void updateItemInDatabaseHelper(Context context, final ContentValues values, final ItemInfo item, final String callingFunction) { final long itemId = item.id; final Uri uri = LauncherSettings.Favorites.getContentUri(itemId); final ContentResolver cr = context.getContentResolver(); final StackTraceElement[] stackTrace = new Throwable().getStackTrace(); Runnable r = new Runnable() { public void run() { cr.update(uri, values, null, null); updateItemArrays(item, itemId, stackTrace); } }; runOnWorkerThread(r); }
Example 11
Source File: MediaStoreService.java From Popeens-DSub with GNU General Public License v3.0 | 5 votes |
public void renameInMediaStore(File start, File end) { ContentResolver contentResolver = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, end.getAbsolutePath()); int n = contentResolver.update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values, MediaStore.MediaColumns.DATA + "=?", new String[]{start.getAbsolutePath()}); if (n > 0) { Log.i(TAG, "Rename media store row for " + start + " to " + end); } }
Example 12
Source File: ContactsHelper.java From AndroidBase with Apache License 2.0 | 5 votes |
/** * 修改联系人数据 */ public boolean update(String name, String phoneNumber) { Cursor cursor = null; try { //根据姓名求id,再根据id删除 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); ContentResolver resolver = mContext.getContentResolver(); cursor = resolver.query(uri, new String[]{Data._ID}, "display_name=?", new String[]{name}, null); if (cursor != null) { if (cursor.moveToFirst()) { int id = cursor.getInt(0); Uri mUri = Uri.parse("content://com.android.contacts/data");//对data表的所有数据操作 ContentResolver mResolver = mContext.getContentResolver(); ContentValues values = new ContentValues(); values.put("data1", phoneNumber); mResolver.update(mUri, values, "mimetype=? and raw_contact_id=?", new String[]{"vnd.android.cursor.item/phone_v2", id + ""}); return true; } } } catch (Exception e) { e.printStackTrace(); }finally { if (cursor != null) { cursor.close(); } } return false; }
Example 13
Source File: ApiCallHandlerThread.java From PADListener with GNU General Public License v2.0 | 5 votes |
private void savePlayerInfo(CapturedPlayerInfoModel playerInfoModel) { MyLog.entry(); final ContentResolver cr = context.getContentResolver(); final Uri uri = CapturedPlayerInfoDescriptor.UriHelper.uriForAll(); Long fake_id = null; final Cursor cursor = cr.query(uri, new String[]{CapturedPlayerInfoDescriptor.Fields.FAKE_ID.getColName()}, null, null, null); if (cursor != null) { if (cursor.moveToNext()) { fake_id = cursor.getLong(0); } cursor.close(); } final ContentValues values = CapturedPlayerInfoProviderHelper.modelToValues(playerInfoModel); if (fake_id == null) { MyLog.debug("Insert new data"); cr.insert(uri, values); } else { MyLog.debug("Update existing data"); cr.update(uri, values, CapturedPlayerInfoDescriptor.Fields.FAKE_ID.getColName() + " = ?", new String[]{fake_id.toString()}); } MyLog.exit(); }
Example 14
Source File: SimplePreferences.java From callmeter with GNU General Public License v3.0 | 4 votes |
/** * Save preferences to plans. */ static void savePrefs(final Context context) { Log.d(TAG, "savePrefs()"); SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); ContentResolver cr = context.getContentResolver(); ContentValues cv = new ContentValues(); // common String s = p.getString(PREFS_BILLDAY, "1").replace(".", ""); Log.d(TAG, "billday: ", s); int i = Utils.parseInt(s, 1); Log.d(TAG, "billday: ", i); Calendar c = Calendar.getInstance(); c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), i, 1, 0, 1); if (c.getTimeInMillis() > System.currentTimeMillis()) { c.add(Calendar.MONTH, -1); } Log.d(TAG, "bd: ", DateFormat.getDateFormat(context).format(c.getTime())); cv.clear(); cv.put(DataProvider.Plans.BILLDAY, c.getTimeInMillis()); cv.put(DataProvider.Plans.BILLPERIOD, DataProvider.BILLPERIOD_1MONTH); cr.update(DataProvider.Plans.CONTENT_URI, cv, SELECTION_TYPE, new String[]{String.valueOf(DataProvider.TYPE_BILLPERIOD)}); // calls savePrefsCall(p, cr, 16, ""); savePrefsCall(p, cr, 31, "_2"); savePrefsCall(p, cr, 30, "_voip"); // sms savePrefsSMS(p, cr, 20, ""); savePrefsSMS(p, cr, 34, "_2"); savePrefsSMS(p, cr, 29, "_websms"); // mms cv.clear(); s = p.getString(PREFS_FREEMMS, "0"); i = Utils.parseInt(s, 0); if (i > 0) { cv.put(DataProvider.Plans.LIMIT_TYPE, DataProvider.LIMIT_TYPE_UNITS); } else { cv.put(DataProvider.Plans.LIMIT_TYPE, DataProvider.LIMIT_TYPE_NONE); } cv.put(DataProvider.Plans.LIMIT, i); cv.put(DataProvider.Plans.COST_PER_ITEM, Utils.parseFloat(p.getString(PREFS_COST_PER_MMS, "0"), 0f)); cr.update(DataProvider.Plans.CONTENT_URI, cv, SELECTION_ID, new String[]{"28"}); // data cv.clear(); s = p.getString(PREFS_FREEDATA, "0"); i = Utils.parseInt(s, 0); if (i > 0) { cv.put(DataProvider.Plans.LIMIT_TYPE, DataProvider.LIMIT_TYPE_UNITS); } else { cv.put(DataProvider.Plans.LIMIT_TYPE, DataProvider.LIMIT_TYPE_NONE); } cv.put(DataProvider.Plans.LIMIT, i); float f = Utils.parseFloat(p.getString(PREFS_COST_PER_MB, "0"), 0f); cv.put(DataProvider.Plans.COST_PER_AMOUNT1, f); cv.put(DataProvider.Plans.COST_PER_AMOUNT2, f); cr.update(DataProvider.Plans.CONTENT_URI, cv, SELECTION_TYPE, new String[]{String.valueOf(DataProvider.TYPE_DATA)}); }
Example 15
Source File: CarrierIdInstallReceiver.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override protected void postInstall(Context context, Intent intent) { ContentResolver resolver = context.getContentResolver(); resolver.update(Uri.withAppendedPath(Telephony.CarrierId.All.CONTENT_URI, "update_db"), new ContentValues(), null, null); }
Example 16
Source File: AppWidgetsRestoredReceiver.java From Trebuchet with GNU General Public License v3.0 | 4 votes |
/** * Updates the app widgets whose id has changed during the restore process. */ static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds) { final ContentResolver cr = context.getContentResolver(); final List<Integer> idsToRemove = new ArrayList<Integer>(); final AppWidgetManager widgets = AppWidgetManager.getInstance(context); for (int i = 0; i < oldWidgetIds.length; i++) { Log.i(TAG, "Widget state restore id " + oldWidgetIds[i] + " => " + newWidgetIds[i]); final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]); final int state; if (LauncherModel.isValidProvider(provider)) { // This will ensure that we show 'Click to setup' UI if required. state = LauncherAppWidgetInfo.FLAG_UI_NOT_READY; } else { state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY; } ContentValues values = new ContentValues(); values.put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i]); values.put(LauncherSettings.Favorites.RESTORED, state); String[] widgetIdParams = new String[] { Integer.toString(oldWidgetIds[i]) }; int result = cr.update(Favorites.CONTENT_URI, values, "appWidgetId=? and (restored & 1) = 1", widgetIdParams); if (result == 0) { Cursor cursor = cr.query(Favorites.CONTENT_URI, new String[] {Favorites.APPWIDGET_ID}, "appWidgetId=?", widgetIdParams, null); try { if (!cursor.moveToFirst()) { // The widget no long exists. idsToRemove.add(newWidgetIds[i]); } } finally { cursor.close(); } } } // Unregister the widget IDs which are not present on the workspace. This could happen // when a widget place holder is removed from workspace, before this method is called. if (!idsToRemove.isEmpty()) { final AppWidgetHost appWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID); new AsyncTask<Void, Void, Void>() { public Void doInBackground(Void ... args) { for (Integer id : idsToRemove) { appWidgetHost.deleteAppWidgetId(id); Log.e(TAG, "Widget no longer present, appWidgetId=" + id); } return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); } LauncherAppState app = LauncherAppState.getInstanceNoCreate(); if (app != null) { app.reloadWorkspace(); } }
Example 17
Source File: CalendarController.java From offline-calendar with GNU General Public License v3.0 | 4 votes |
/** * Update values of existing calendar with id */ public static void updateCalendar(long id, String displayName, int color, ContentResolver cr) { Uri calUri = ContentUris.withAppendedId(buildCalUri(), id); ContentValues cv = buildContentValues(displayName, color); cr.update(calUri, cv, null, null); }
Example 18
Source File: PreferencesContentValues.java From PreferencesProvider with Apache License 2.0 | 2 votes |
/** * Update row(s) using the values stored by this object and the given selection. * * @param contentResolver The content resolver to use. * @param where The selection to use (can be {@code null}). * @return count of updated rows. */ public int update(ContentResolver contentResolver, @Nullable PreferencesSelection where) { return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args()); }
Example 19
Source File: OnboardingManager.java From zom-android-matrix with Apache License 2.0 | 2 votes |
public static void addExistingAccount (Activity context, Handler handler, String username, String domain, String password, OnboardingListener onboardingListener) { final OnboardingAccount result = new OnboardingAccount(); int port = 5222; ContentResolver cr = context.getContentResolver(); ImPluginHelper helper = ImPluginHelper.getInstance(context); long providerId = helper.createAdditionalProvider(helper.getProviderNames().get(0)); //xmpp FIXME long accountId = ImApp.insertOrUpdateAccount(cr, providerId, -1, username, username, password); if (accountId == -1) return; Uri accountUri = ContentUris.withAppendedId(Imps.Account.CONTENT_URI, accountId); Cursor pCursor = cr.query(Imps.ProviderSettings.CONTENT_URI, new String[]{Imps.ProviderSettings.NAME, Imps.ProviderSettings.VALUE}, Imps.ProviderSettings.PROVIDER + "=?", new String[]{Long.toString(providerId)}, null); Imps.ProviderSettings.QueryMap settings = new Imps.ProviderSettings.QueryMap( pCursor, cr, providerId, false /* don't keep updated */, null /* no handler */); //should check to see if Orbot is installed and running boolean doDnsSrvLookup = true; settings.setRequireTls(true); settings.setTlsCertVerify(true); settings.setAllowPlainAuth(false); settings.setDoDnsSrv(doDnsSrvLookup); String newDeviceId = DEFAULT_DEVICE_NAME + "-" + UUID.randomUUID().toString().substring(0, 8); settings.setDeviceName(newDeviceId); try { settings.setDomain(domain); settings.setPort(port); settings.requery(); result.username = username; result.domain = domain; result.password = password; result.providerId = providerId; result.accountId = accountId; //now keep this account signed-in ContentValues values = new ContentValues(); values.put(Imps.AccountColumns.KEEP_SIGNED_IN, 1); cr.update(accountUri, values, null, null); settings.requery(); if (Looper.myLooper() == null) Looper.prepare(); final MatrixConnection conn = new MatrixConnection(context); conn.initUser(providerId, accountId); conn.checkAccount(accountId, password, providerId, new MatrixConnection.LoginListener() { @Override public void onLoginSuccess() { onboardingListener.registrationSuccessful(result); } @Override public void onLoginFailed(String message) { onboardingListener.registrationFailed(message); } }); // settings closed in registerAccount } catch (Exception e) { LogCleaner.error(LOG_TAG, "error registering new account", e); onboardingListener.registrationFailed(e.getMessage()); } settings.close(); }
Example 20
Source File: RemoteImService.java From Zom-Android-XMPP with GNU General Public License v3.0 | 2 votes |
/** private void clearMemoryMedium () { mOtrChatManager = null; for (ImConnectionAdapter conn : mConnections.values()) { conn.clearMemory(); } for (ImConnectionAdapter conn : mConnectionsByUser.values()) { conn.clearMemory(); } System.gc(); } private void clearMemoryComplete () { clearMemoryMedium (); for (ImConnectionAdapter conn : mConnections.values()) { conn.suspend(); } for (ImConnectionAdapter conn : mConnectionsByUser.values()) { conn.suspend(); } SecureMediaStore.unmount(); System.gc(); openEncryptedStores(tempKey,true); }**/ private void clearConnectionStatii() { ContentResolver cr = getContentResolver(); ContentValues values = new ContentValues(2); values.put(Imps.AccountStatus.PRESENCE_STATUS, Imps.Presence.OFFLINE); values.put(Imps.AccountStatus.CONNECTION_STATUS, Imps.ConnectionStatus.OFFLINE); try { //insert on the "account_status" uri actually replaces the existing value cr.update(Imps.AccountStatus.CONTENT_URI, values, null, null); } catch (Exception e) { //this can throw NPE on restart sometimes if database has not been unlocked debug("database is not unlocked yet. caught NPE from mDbHelper in ImpsProvider"); } }