List of usage examples for android.content ContentResolver delete
public final int delete(@RequiresPermission.Write @NonNull Uri url, @Nullable String where, @Nullable String[] selectionArgs)
From source file:us.parshall.ezandroid.activity.EZItemListActivity.java
protected OnClickListener deleteItemsListener(final EZItemListActivity activity, final String tableName) { return new DialogInterface.OnClickListener() { @Override/*from ww w .j a va2 s.c o m*/ public void onClick(DialogInterface dialog, int which) { long[] selectedItemIds = activity.getListView().getCheckedItemIds(); String[] itemIds = new String[selectedItemIds.length]; String[] parameters = new String[selectedItemIds.length]; for (int i = 0; i < selectedItemIds.length; i++) { itemIds[i] = String.valueOf(selectedItemIds[i]); parameters[i] = "?"; } String where = EZContentProvider.KEY_ID + " in ( " + TextUtils.join(",", parameters) + " )"; ContentResolver cr = activity.getContentResolver(); cr.delete(Uri.withAppendedPath(EZContentProvider.CONTENT_URI, tableName), where, itemIds); cr.notifyChange(Uri.withAppendedPath(EZContentProvider.CONTENT_URI, tableName), null); dialog.dismiss(); activity.finish(); activity.startActivity(activity.getIntent()); } }; }
From source file:net.naonedbus.manager.impl.CommentaireManager.java
public void clear(final ContentResolver contentResolver) { contentResolver.delete(CommentaireProvider.CONTENT_URI, null, null); }
From source file:com.antew.redditinpictures.library.reddit.LoginResponse.java
@Override public void processHttpResponse(Context context) { ContentResolver resolver = context.getContentResolver(); // Delete old logins resolver.delete(RedditContract.Login.CONTENT_URI, null, null); RedditLoginResponse response = JsonDeserializer.deserialize(result.getJson(), RedditLoginResponse.class); if (response == null) { Ln.e("Error parsing Reddit login response"); return;/*from w ww . ja v a 2 s . co m*/ } // The username isn't sent back with the login response, so we have it passed // through from the login request String username = BundleUtil.getString(result.getExtraData(), RedditContract.Login.USERNAME, null); if (response.getLoginResponse() != null && response.getLoginResponse().getData() != null) { response.getLoginResponse().getData().setUsername(username); } ContentValues loginValues = response.getContentValues(); Intent loginNotify = new Intent(Constants.Broadcast.BROADCAST_LOGIN_COMPLETE); loginNotify.putExtra(Constants.Extra.EXTRA_USERNAME, username); Integer loginSuccess = loginValues.getAsInteger(RedditContract.Login.SUCCESS); if (loginSuccess != null && loginSuccess == 1) { loginNotify.putExtra(Constants.Extra.EXTRA_SUCCESS, true); resolver.insert(RedditContract.Login.CONTENT_URI, loginValues); } else { loginNotify.putExtra(Constants.Extra.EXTRA_SUCCESS, false); loginNotify.putExtra(Constants.Extra.EXTRA_ERROR_MESSAGE, loginValues.getAsString(RedditContract.Login.ERROR_MESSAGE)); loginNotify.putExtra(Constants.Extra.EXTRA_USERNAME, username); } LocalBroadcastManager.getInstance(context).sendBroadcast(loginNotify); }
From source file:com.filemanager.free.filesystem.FileUtil.java
/** * Delete a file. May be even on external SD card. * * @param file the file to be deleted.//from w ww. j a v a 2 s . c om * @return True if successfully deleted. */ public static final boolean deleteFile(@NonNull final File file, Context context) { // First try the normal deletion. if (file == null) return true; boolean fileDelete = deleteFilesInFolder(file, context); if (file.delete() || fileDelete) return true; // Try with Storage Access Framework. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && FileUtil.isOnExtSdCard(file, context)) { DocumentFile document = getDocumentFile(file, false, context); return document.delete(); } // Try the Kitkat workaround. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { ContentResolver resolver = context.getContentResolver(); try { Uri uri = MediaStoreHack.getUriFromFile(file.getAbsolutePath(), context); resolver.delete(uri, null, null); return !file.exists(); } catch (Exception e) { Log.e("AmazeFileUtils", "Error when deleting file " + file.getAbsolutePath(), e); return false; } } return !file.exists(); }
From source file:com.metinkale.prayerapp.MainIntentService.java
private void handleCalendarIntegration() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED) { Prefs.setCalendar("-1"); return;// w w w .ja v a2 s. co m } Context context = App.getContext(); try { ContentResolver cr = context.getContentResolver(); cr.delete(CalendarContract.Events.CONTENT_URI, CalendarContract.Events.DESCRIPTION + "=\"com.metinkale.prayer\"", null); String id = Prefs.getCalendar(); if ("-1".equals(id) || (Prefs.getLanguage() == null)) { return; } int year = LocalDate.now().getYear(); Collection<int[]> days = new ArrayList<>(); days.addAll(HicriDate.getHolydays(year)); days.addAll(HicriDate.getHolydays(year + 1)); int i = 0; ContentValues[] events = new ContentValues[days.size()]; for (int[] date : days) { ContentValues event = new ContentValues(); event.put(CalendarContract.Events.CALENDAR_ID, id); event.put(CalendarContract.Events.TITLE, Utils.getHolyday(date[HicriDate.DAY] - 1)); event.put(CalendarContract.Events.DESCRIPTION, "com.metinkale.prayer"); ReadableInstant cal = new DateTime(date[HicriDate.GY], date[HicriDate.GM], date[HicriDate.GD], 0, 0, 0); long dtstart = cal.getMillis(); long dtend = dtstart + DateUtils.DAY_IN_MILLIS; event.put(CalendarContract.Events.DTSTART, dtstart + TimeZone.getDefault().getOffset(dtstart)); event.put(CalendarContract.Events.DTEND, dtend + TimeZone.getDefault().getOffset(dtend)); event.put(CalendarContract.Events.EVENT_TIMEZONE, Time.TIMEZONE_UTC); event.put(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED); event.put(CalendarContract.Events.ALL_DAY, 1); events[i] = event; i++; } cr.bulkInsert(CalendarContract.Events.CONTENT_URI, events); } catch (Exception e) { Prefs.setCalendar("-1"); Crashlytics.logException(e); } }
From source file:com.birkettenterprise.phonelocator.activity.UpdateLogActivity.java
private void clearLog() { ContentResolver cr = getContentResolver(); cr.delete(UpdateLogDatabaseContentProvider.URI, null, null); }
From source file:com.manning.androidhacks.hack023.dao.TodoDAO.java
public int forcedDeleteTodo(ContentResolver contentResolver, Long id) { return contentResolver.delete(TodoContentProvider.CONTENT_URI, TodoContentProvider.COLUMN_SERVER_ID + "=" + id, null); }
From source file:com.manning.androidhacks.hack023.dao.TodoDAO.java
public int deleteTodoForced(ContentResolver contentResolver, long id) { return contentResolver.delete(TodoContentProvider.CONTENT_URI, TodoContentProvider.COLUMN_SERVER_ID + "=" + id, null); }
From source file:com.piusvelte.wapdroid.ManageData.java
@Override public boolean onContextItemSelected(MenuItem item) { int id = (int) ((AdapterContextMenuInfo) item.getMenuInfo()).id; if (item.getItemId() == R.id.menu_remove) { ContentResolver contentResolver = getActivity().getContentResolver(); contentResolver.delete(Networks.CONTENT_URI, Networks._ID + "=?", new String[] { String.valueOf(id) }); BackupManager.dataChanged(getActivity()); }/* w w w .j a v a 2s. c o m*/ return super.onContextItemSelected(item); }
From source file:org.onebusaway.android.ui.MyRemindersFragment.java
private void deleteTrip(ListView l, int position) { String[] ids = getIds(l, position); // TODO: Confirmation dialog? ContentResolver cr = getActivity().getContentResolver(); cr.delete(ObaContract.Trips.buildUri(ids[0], ids[1]), null, null); TripService.scheduleAll(getActivity()); getLoaderManager().getLoader(0).onContentChanged(); }