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.android.leanlauncher.LauncherModel.java
static void updateItemInDatabaseHelper(Context context, final ContentValues values, final ItemInfo item) { final long itemId = item.id; final Uri uri = LauncherSettings.Favorites.getContentUri(itemId, false); final ContentResolver cr = context.getContentResolver(); Runnable r = new Runnable() { public void run() { cr.update(uri, values, null, null); updateItemArrays(item, itemId); }// w ww . j ava 2 s .c o m }; runOnWorkerThread(r); }
From source file:org.inftel.ssa.mobile.ui.fragments.ProjectEditFragment.java
public void saveProject() throws ParseException { Log.d(getClass().getSimpleName(), "Save Project"); ContentResolver cr = mActivity.getContentResolver(); ContentValues values = new ContentValues(); values.put(Projects.PROJECT_NAME, title.getText().toString()); values.put(Projects.PROJECT_SUMMARY, summary.getText().toString()); values.put(Projects.PROJECT_DESCRIPTION, description.getText().toString()); values.put(Projects.PROJECT_STARTED, secureEpochDate(started.getText().toString())); values.put(Projects.PROJECT_CLOSE, secureEpochDate(finished.getText().toString())); values.put(Projects.PROJECT_COMPANY, company.getText().toString()); values.put(Projects.PROJECT_LICENSE, license.getText().toString()); try {//from w ww . j a va2 s. c o m if (mState == STATE_INSERT) { values.put(Projects.SYNC_STATUS, SsaContract.STATUS_CREATED); values.put(Projects.PROJECT_OPENED, Long.toString(System.currentTimeMillis())); cr.insert(Projects.CONTENT_URI, values); } else { values.put(Projects.SYNC_STATUS, SsaContract.STATUS_DIRTY); cr.update(mContentUri, values, null, null); } } catch (NullPointerException e) { Log.e(getClass().getSimpleName(), e.getMessage()); } }
From source file:info.guardianproject.otr.app.im.service.RemoteImService.java
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 {//from w w w.j a va2 s .co m //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"); } }
From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from w w w . ja va 2s . com*/ Context context = getContext(); App.getApiManager().getEarthquakeService().getData().enqueue(new Callback<EarthquakeObject>() { @Override public void onResponse(Call<EarthquakeObject> call, Response<EarthquakeObject> response) { EarthquakeObject earthquake = response.body(); Vector<ContentValues> cVVector = new Vector<>(earthquake.getFeatures().size()); double currentBiggest = 0.0; ContentValues notifyValues = null; for (Feature each : earthquake.getFeatures()) { ContentValues earthquakeValues = new ContentValues(); earthquakeValues.put(EarthquakeColumns.PLACE, each.getProperties().getPlace()); earthquakeValues.put(EarthquakeColumns.ID_EARTH, each.getId()); earthquakeValues.put(EarthquakeColumns.MAG, each.getProperties().getMag()); earthquakeValues.put(EarthquakeColumns.TYPE, each.getProperties().getType()); earthquakeValues.put(EarthquakeColumns.ALERT, each.getProperties().getAlert()); earthquakeValues.put(EarthquakeColumns.TIME, each.getProperties().getTime()); earthquakeValues.put(EarthquakeColumns.URL, each.getProperties().getUrl()); earthquakeValues.put(EarthquakeColumns.DETAIL, each.getProperties().getDetail()); earthquakeValues.put(EarthquakeColumns.DEPTH, each.getGeometry().getCoordinates().get(2)); earthquakeValues.put(EarthquakeColumns.LONGITUDE, each.getGeometry().getCoordinates().get(0)); earthquakeValues.put(EarthquakeColumns.LATITUDE, each.getGeometry().getCoordinates().get(1)); LatLng latLng = new LatLng(each.getGeometry().getCoordinates().get(1), each.getGeometry().getCoordinates().get(0)); LatLng location = LocationUtils.getLocation(context); earthquakeValues.put(EarthquakeColumns.DISTANCE, LocationUtils.getDistance(latLng, location)); cVVector.add(earthquakeValues); if (each.getProperties().getMag() != null && each.getProperties().getMag() > currentBiggest) { currentBiggest = each.getProperties().getMag(); notifyValues = new ContentValues(earthquakeValues); notifyValues.put(EarthquakeColumns.PLACE, Utilities.formatEarthquakePlace(each.getProperties().getPlace())); } } int inserted = 0; // add to database ContentResolver resolver = context.getContentResolver(); if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = resolver.bulkInsert(EarthquakeColumns.CONTENT_URI, cvArray); } // Set the date to day minus one to delete old data from the database Date date = new Date(); date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS); int deleted = resolver.delete(EarthquakeColumns.CONTENT_URI, EarthquakeColumns.TIME + " <= ?", new String[] { String.valueOf(date.getTime()) }); Log.v(TAG, "Service Complete. " + inserted + " Inserted, " + deleted + " deleted"); sendNotification(notifyValues); } @Override public void onFailure(Call<EarthquakeObject> call, Throwable t) { Log.e(TAG, "onFailure: " + t.toString()); } }); App.getNewsManager().getNewsService().getNews().enqueue(new Callback<Rss>() { @Override public void onResponse(Call<Rss> call, Response<Rss> response) { Channel news = response.body().getChannel(); Vector<ContentValues> cVVector = new Vector<>(news.getItem().size()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.getDefault()); Date date = new Date(); for (Item each : news.getItem()) { ContentValues weatherValues = new ContentValues(); try { date = simpleDateFormat.parse(each.getPubDate()); } catch (ParseException e) { Log.e(TAG, "e:" + e); } weatherValues.put(NewsColumns.DATE, date.getTime()); weatherValues.put(NewsColumns.TITLE, each.getTitle()); weatherValues.put(NewsColumns.DESCRIPTION, Html.toHtml(new SpannedString(each.getDescription()))); weatherValues.put(NewsColumns.URL, each.getLink()); weatherValues.put(NewsColumns.GUID, each.getGuid().getContent()); cVVector.add(weatherValues); } int inserted = 0; // add to database ContentResolver resolver = getContext().getContentResolver(); if (cVVector.size() > 0) { // Student: call bulkInsert to add the weatherEntries to the database here ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = resolver.bulkInsert(NewsColumns.CONTENT_URI, cvArray); } // Set the date to day minus two to delete old data from the database date = new Date(); date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS * 3); int deleted = resolver.delete(NewsColumns.CONTENT_URI, NewsColumns.DATE + " <= ?", new String[] { String.valueOf(date.getTime()) }); } @Override public void onFailure(Call<Rss> call, Throwable t) { Log.e(TAG, "onFailure: " + t.toString()); } }); // TODO: 4/22/16 possible refactoring //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String lastNotificationKey = context.getString(R.string.sharedprefs_key_last_countupdate); long lastSync = prefs.getLong(lastNotificationKey, DateUtils.DAY_IN_MILLIS); if (System.currentTimeMillis() - lastSync >= Utilities.getSyncIntervalPrefs(context) * DateUtils.SECOND_IN_MILLIS) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US); Date date = new Date(System.currentTimeMillis()); String startTime[] = new String[] { simpleDateFormat.format(date.getTime() - DateUtils.YEAR_IN_MILLIS), simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS * 30), simpleDateFormat.format(date.getTime() - DateUtils.WEEK_IN_MILLIS), simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS) }; String endTime = simpleDateFormat.format(date); int iterator = 1; while (iterator < CountColumns.ALL_COLUMNS.length) { final int round = iterator; App.getApiManager().getEarthquakeService().getEarthquakeStats(startTime[round - 1], endTime) .enqueue(new Callback<CountEarthquakes>() { @Override public void onResponse(Call<CountEarthquakes> call, Response<CountEarthquakes> response) { ContentValues count = new ContentValues(); count.put(CountColumns.ALL_COLUMNS[round], response.body().getCount()); ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query(CountColumns.CONTENT_URI, null, null, null, null); if (cursor != null) { if (cursor.getCount() < 1) { long inserted = ContentUris .parseId(contentResolver.insert(CountColumns.CONTENT_URI, count)); //Log.d(TAG, "inserted:" + inserted); } else { int updated = contentResolver.update(CountColumns.CONTENT_URI, count, CountColumns._ID + " = ?", new String[] { "1" }); //Log.d(TAG, "updated: " + updated); } cursor.close(); } } @Override public void onFailure(Call<CountEarthquakes> call, Throwable t) { Log.e(TAG, "Error: " + t); } }); iterator++; } //refreshing last sync prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).apply(); } // notify PagerActivity that data has been updated context.getContentResolver().notifyChange(EarthquakeColumns.CONTENT_URI, null, false); context.getContentResolver().notifyChange(NewsColumns.CONTENT_URI, null, false); context.getContentResolver().notifyChange(CountColumns.CONTENT_URI, null, false); updateWidgets(); }
From source file:com.bt.download.android.gui.Librarian.java
public String renameFile(FileDescriptor fd, String newFileName) { try {//from w w w. ja v a 2 s. c om String filePath = fd.filePath; File oldFile = new File(filePath); String ext = FilenameUtils.getExtension(filePath); File newFile = new File(oldFile.getParentFile(), newFileName + '.' + ext); ContentResolver cr = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(MediaColumns.DATA, newFile.getAbsolutePath()); values.put(MediaColumns.DISPLAY_NAME, FilenameUtils.getBaseName(newFileName)); values.put(MediaColumns.TITLE, FilenameUtils.getBaseName(newFileName)); TableFetcher fetcher = TableFetchers.getFetcher(fd.fileType); cr.update(fetcher.getContentUri(), values, BaseColumns._ID + "=?", new String[] { String.valueOf(fd.id) }); oldFile.renameTo(newFile); return newFile.getAbsolutePath(); } catch (Throwable e) { Log.e(TAG, "Failed to rename file: " + fd, e); } return null; }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public int update(Uri uri, ContentValues values) { ContentResolver resolver = Mechanoid.getContentResolver(); return resolver.update(uri, values, toString(), getArgsArray()); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public int update(Uri uri, ContentValues values, boolean notifyChange) { uri = uri.buildUpon()// w ww .j a v a2 s . c o m .appendQueryParameter(MechanoidContentProvider.PARAM_NOTIFY, String.valueOf(notifyChange)).build(); ContentResolver resolver = Mechanoid.getContentResolver(); return resolver.update(uri, values, toString(), getArgsArray()); }
From source file:org.zywx.wbpalmstar.plugin.uexcontacts.PFConcactMan.java
public static boolean modify(Context context, ModifyOptionVO modifyOptionVO) { String contactId = modifyOptionVO.getContactId(); String inName = modifyOptionVO.getName(); String inNum = modifyOptionVO.getNum(); String inEmail = modifyOptionVO.getEmail(); int sdkVersion = Build.VERSION.SDK_INT; ContentResolver contentResolver = context.getContentResolver(); boolean isModify = false; if (sdkVersion < 8) { try {/* www .j av a 2s .c om*/ Cursor cusor = null; String[] projection = new String[] { android.provider.Contacts.People._ID, android.provider.Contacts.People.NAME, android.provider.Contacts.People.NUMBER }; String selection = android.provider.Contacts.People._ID + " = ? "; String[] selectionArgs = new String[] { contactId }; cusor = contentResolver.query(android.provider.Contacts.People.CONTENT_URI, projection, selection, selectionArgs, null); cusor.moveToFirst(); while (cusor.moveToNext()) { ContentValues values = new ContentValues(); String nameWhere = android.provider.Contacts.Phones.PERSON_ID + "=? "; values.put(android.provider.Contacts.People.NAME, inName); contentResolver.update(android.provider.Contacts.People.CONTENT_URI, values, nameWhere, selectionArgs); // ??type?????? values.clear(); values.put(android.provider.Contacts.Phones.TYPE, android.provider.Contacts.Phones.TYPE_MOBILE); values.put(android.provider.Contacts.Phones.NUMBER, inNum); String numWhere = android.provider.Contacts.Phones.PERSON_ID + "=? "; contentResolver.update(android.provider.Contacts.Phones.CONTENT_URI, values, numWhere, selectionArgs); // ?type????? values.clear(); values.put(android.provider.Contacts.ContactMethods.KIND, android.provider.Contacts.KIND_EMAIL); values.put(android.provider.Contacts.ContactMethods.DATA, inEmail); values.put(android.provider.Contacts.ContactMethods.TYPE, android.provider.Contacts.ContactMethods.TYPE_HOME); String emailWhere = android.provider.Contacts.ContactMethods.PERSON_ID + "=? "; contentResolver.update(android.provider.Contacts.ContactMethods.CONTENT_URI, values, emailWhere, selectionArgs); isModify = true; } if (cusor != null) cusor.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); return false; } } else if (sdkVersion < 14) { try { String[] projection = new String[] { android.provider.ContactsContract.Contacts.DISPLAY_NAME, android.provider.ContactsContract.Contacts._ID }; String selection = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? "; String[] selectionArgs = new String[] { contactId }; Cursor cur = contentResolver.query(android.provider.ContactsContract.RawContacts.CONTENT_URI, projection, selection, selectionArgs, null); cur.moveToFirst(); while (cur.moveToNext()) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, inName); String nameWhere = android.provider.ContactsContract.Data.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE); String numWhere = android.provider.ContactsContract.Data.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] numSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, numWhere, numSelection); values.clear(); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.Data.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; context.getContentResolver().update(android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; } if (cur != null) cur.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } } else { try { String[] projection = new String[] { android.provider.ContactsContract.Contacts.DISPLAY_NAME, android.provider.ContactsContract.RawContacts._ID }; String selection = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? "; String[] selectionArgs = new String[] { contactId }; Cursor cur = contentResolver.query(android.provider.ContactsContract.RawContacts.CONTENT_URI, projection, selection, selectionArgs, null); while (cur.moveToNext()) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, inName); String nameWhere = android.provider.ContactsContract.Data.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }; int resultId = context.getContentResolver().update( android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.PhoneLookup.NUMBER); String numWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] numSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; int resultId1 = context.getContentResolver().update( android.provider.ContactsContract.Data.CONTENT_URI, values, numWhere, numSelection); values.clear(); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; int resultId2 = context.getContentResolver().update( android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; } if (cur != null) cur.close(); projection = new String[] { android.provider.ContactsContract.Contacts.DISPLAY_NAME, android.provider.ContactsContract.Contacts._ID }; selection = android.provider.ContactsContract.Contacts._ID + " = ? "; Cursor cursor = context.getContentResolver().query( android.provider.ContactsContract.Contacts.CONTENT_URI, projection, selection, selectionArgs, null); while (cursor.moveToNext()) { ContentValues values = new ContentValues(); values.clear(); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, inName); String nameWhere = android.provider.ContactsContract.Data.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] nameSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE }; int resultId3 = context.getContentResolver().update( android.provider.ContactsContract.Data.CONTENT_URI, values, nameWhere, nameSelection); values.clear(); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.NUMBER, inNum); values.put(android.provider.ContactsContract.CommonDataKinds.Phone.TYPE, android.provider.ContactsContract.PhoneLookup.NUMBER); String numWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] numSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE, }; int resultId4 = context.getContentResolver().update( android.provider.ContactsContract.Data.CONTENT_URI, values, numWhere, numSelection); values.clear(); values.put(android.provider.ContactsContract.Data.MIMETYPE, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); values.put(android.provider.ContactsContract.CommonDataKinds.Email.DATA, inEmail); values.put(android.provider.ContactsContract.CommonDataKinds.Email.TYPE, android.provider.ContactsContract.CommonDataKinds.Email.TYPE_WORK); String emailWhere = android.provider.ContactsContract.RawContacts.CONTACT_ID + " = ? AND " + android.provider.ContactsContract.Data.MIMETYPE + " = ?"; String[] emailSelection = new String[] { contactId, android.provider.ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE, }; int resultId5 = context.getContentResolver().update( android.provider.ContactsContract.Data.CONTENT_URI, values, emailWhere, emailSelection); isModify = true; } if (cursor != null) cursor.close(); try { Cursor cusor = null; projection = new String[] { android.provider.Contacts.People._ID, android.provider.Contacts.People.NAME, android.provider.Contacts.People.NUMBER }; selection = android.provider.Contacts.People._ID + " = ? "; cusor = contentResolver.query(android.provider.Contacts.People.CONTENT_URI, projection, selection, selectionArgs, null); cusor.moveToFirst(); while (cusor.moveToNext()) { ContentValues values = new ContentValues(); String nameWhere = android.provider.Contacts.Phones.PERSON_ID + "=? "; values.put(android.provider.Contacts.People.NAME, inName); contentResolver.update(android.provider.Contacts.People.CONTENT_URI, values, nameWhere, selectionArgs); // ??type?????? values.clear(); values.put(android.provider.Contacts.Phones.TYPE, android.provider.Contacts.Phones.TYPE_MOBILE); values.put(android.provider.Contacts.Phones.NUMBER, inNum); String numWhere = android.provider.Contacts.Phones.PERSON_ID + "=? "; String[] numWhereParams = { contactId }; contentResolver.update(android.provider.Contacts.Phones.CONTENT_URI, values, numWhere, numWhereParams); // ?type????? values.clear(); values.put(android.provider.Contacts.ContactMethods.KIND, android.provider.Contacts.KIND_EMAIL); values.put(android.provider.Contacts.ContactMethods.DATA, inEmail); values.put(android.provider.Contacts.ContactMethods.TYPE, android.provider.Contacts.ContactMethods.TYPE_HOME); String emailWhere = android.provider.Contacts.ContactMethods.PERSON_ID + "=? "; String[] emailWhereParams = { contactId }; contentResolver.update(android.provider.Contacts.ContactMethods.CONTENT_URI, values, emailWhere, emailWhereParams); isModify = true; } if (cusor != null) cusor.close(); } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); return false; } } catch (Exception e) { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } } if (isModify) { ToastShow(context, finder.getString(context, "plugin_contact_modify_succeed")); } else { ToastShow(context, finder.getString(context, "plugin_contact_modify_fail")); } return isModify; }
From source file:cz.maresmar.sfm.view.portal.PortalDetailFragment.java
@NonNull @Override/*from w ww. ja v a2 s. c o m*/ public Uri saveData() { Timber.i("Saving portal data"); // Defines an object to contain the new values to insert ContentValues values = new ContentValues(); /* * Sets the values of each column and inserts the word. The arguments to the "put" * method are "column name" and "value" */ values.put(ProviderContract.Portal.NAME, mNameText.getText().toString()); values.put(ProviderContract.Portal.REFERENCE, mRefText.getText().toString()); values.put(ProviderContract.Portal.PLUGIN, getSelectedPluginId()); int[] ids = getResources().getIntArray(R.array.connection_security_ids); int selectedId = ids[mSecuritySpinner.getSelectedItemPosition()]; values.put(ProviderContract.Portal.SECURITY, selectedId); if (mLocation != null) { values.put(ProviderContract.Portal.LOC_N, mLocation.latitude); values.put(ProviderContract.Portal.LOC_E, mLocation.longitude); } values.put(ProviderContract.Portal.EXTRA, getExtraData()); // New menu notification @ProviderContract.PortalFlags int flags; if (mNewMenuNotificationCheckBox.isChecked()) { flags = 0; } else { flags = ProviderContract.PORTAL_FLAG_DISABLE_NEW_MENU_NOTIFICATION; } values.put(ProviderContract.Portal.FLAGS, flags); //noinspection ConstantConditions ContentResolver contentResolver = getContext().getContentResolver(); if (mPortalUri == null) { // Ads new portal group mPortalGroupTempUri = contentResolver.insert(ProviderContract.PortalGroup.getUri(), null); //noinspection ConstantConditions long portalGroupId = Long.parseLong(mPortalGroupTempUri.getLastPathSegment()); // Ads portal group to values values.put(ProviderContract.Portal.PORTAL_GROUP_ID, portalGroupId); // Insert them mPortalTempUri = contentResolver.insert(ProviderContract.Portal.getUri(), values); mPortalUri = mPortalTempUri; } else { int updatedRows = contentResolver.update(mPortalUri, values, null, null); if (BuildConfig.DEBUG) { Assert.isOne(updatedRows); } } return mPortalUri; }