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:net.niyonkuru.koodroid.service.SessionService.java
private void login(String email, String password) throws IOException { try {// w w w .j a v a2 s . c o m mPostRequest = new HttpPost(new URI(Config.LOGIN_URL)); } catch (URISyntaxException e) { throw new ServiceException(e.getMessage()); } List<NameValuePair> formData = buildFormData(email, password, getString(R.string.locale)); try { /* fill the login request with form values */ mPostRequest.setEntity(new UrlEncodedFormEntity(formData, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new ServiceException(e.getMessage()); } Document doc; try { final HttpResponse response = mHttpClient.execute(mPostRequest); final Integer status = response.getStatusLine().getStatusCode(); /* scumbag server did not return a 200 code */ if (status != HttpStatus.SC_OK) throw new ServiceException(status.toString()); HttpEntity entity = response.getEntity(); doc = Jsoup.parse(EntityUtils.toString(response.getEntity())); if (entity != null) { entity.consumeContent(); } } catch (UnknownHostException e) { throw new ServiceException(e.getMessage()); } catch (ConnectTimeoutException e) { throw new ServiceException(getString(R.string.error_connection_timeout)); } catch (ClientProtocolException e) { throw new ServiceException(e.getMessage()); } catch (ParseException e) { throw new ServiceException(e.getMessage()); } catch (SocketTimeoutException e) { throw new ServiceException(getString(R.string.error_response_timeout)); } catch (IOException e) { // This could be caused by closing the httpclient connection manager throw new ServiceException(e.getMessage()); } final Resources resources = getResources(); final ContentResolver resolver = getContentResolver(); /* this is a new user logging in */ if (!email.equalsIgnoreCase(mSettings.email())) { /* clear old preferences */ resolver.delete(Settings.CONTENT_URI, null, null); } try { new SubscribersHandler(resources, email).parseAndApply(doc, resolver); new LinksHandler(resources).parseAndApply(doc, resolver); ContentValues values = new ContentValues(3); values.put(Settings.EMAIL, email); values.put(Settings.PASSWORD, password); values.put(Settings.LAST_LOGIN, System.currentTimeMillis()); resolver.insert(Settings.CONTENT_URI, values); new BackupManager(this).dataChanged(); } catch (HandlerException e) { /* check if these errors could be caused by invalid pages */ new ErrorHandler(resources).parseAndThrow(doc); throw e; } }
From source file:net.naonedbus.manager.impl.FavoriManager.java
/** * Remplacer les favoris par ceux de la liste * //from w ww.ja v a 2s . co m * @param contentResolver * @param container */ private void fromList(final ContentResolver contentResolver, final FavoriContainer container) { final ArretManager arretManager = ArretManager.getInstance(); final GroupeManager groupeManager = GroupeManager.getInstance(); final SparseIntArray groupeMapping = new SparseIntArray(); // Delete old items contentResolver.delete(FavoriProvider.CONTENT_URI, null, null); contentResolver.delete(GroupeProvider.CONTENT_URI, null, null); // Add new items for (final net.naonedbus.rest.container.FavoriContainer.Groupe g : container.groupes) { final Groupe groupe = new Groupe(); groupe.setNom(g.nom); groupe.setOrdre(g.ordre); final int idLocal = groupeManager.add(contentResolver, groupe).intValue(); groupeMapping.put(g.id, idLocal); } Integer itemId; final Favori.Builder builder = new Favori.Builder(); for (final net.naonedbus.rest.container.FavoriContainer.Favori f : container.favoris) { builder.setCodeArret(f.codeArret); builder.setCodeSens(f.codeSens); builder.setCodeLigne(f.codeLigne); builder.setNomFavori(f.nomFavori); itemId = arretManager.getIdByFavori(contentResolver, builder.build()); if (itemId != null) { builder.setId(itemId); addFavori(contentResolver, builder.build()); // Associer aux groupes final List<Integer> favoriGroupes = f.idGroupes; if (favoriGroupes != null) for (final Integer idGroupe : favoriGroupes) { if (groupeMapping.indexOfKey(idGroupe) > -1) { groupeManager.addFavoriToGroup(contentResolver, groupeMapping.get(idGroupe), itemId); } } } } }
From source file:com.nononsenseapps.notepad.MainActivity.java
/** * Delete all notes given from database Only marks them as deleted if sync * is enabled/* w ww. jav a2 s .co m*/ * * @param ids */ public static void deleteNotes(Context context, Iterable<Long> ids) { ContentResolver resolver = context.getContentResolver(); boolean shouldMark = shouldMarkAsDeleted(context); for (long id : ids) { Log.d(TAG, "deleteNotes: " + id); if (shouldMark) { ContentValues values = new ContentValues(); values.put(NotePad.Notes.COLUMN_NAME_DELETED, "1"); resolver.update(NotesEditorFragment.getUriFrom(id), values, null, null); } else { resolver.delete(NotesEditorFragment.getUriFrom(id), null, null); } UpdateNotifier.notifyChangeNote(context, NotesEditorFragment.getUriFrom(id)); } }
From source file:org.odk.collect.android.utilities.MediaUtils.java
public static final int deleteAudioFileFromMediaProvider(String audioFile) { ContentResolver cr = Collect.getInstance().getContentResolver(); // audio//from ww w . java 2 s . c om int count = 0; Cursor audioCursor = null; try { String select = Audio.Media.DATA + "=?"; String[] selectArgs = { audioFile }; String[] projection = { Audio.AudioColumns._ID }; audioCursor = cr.query(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, select, selectArgs, null); if (audioCursor.getCount() > 0) { audioCursor.moveToFirst(); List<Uri> audioToDelete = new ArrayList<Uri>(); do { String id = audioCursor.getString(audioCursor.getColumnIndex(Audio.AudioColumns._ID)); audioToDelete.add( Uri.withAppendedPath(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id)); } while (audioCursor.moveToNext()); for (Uri uri : audioToDelete) { Log.i(t, "attempting to delete: " + uri); count += cr.delete(uri, null, null); } } } catch (Exception e) { Log.e(t, e.toString()); } finally { if (audioCursor != null) { audioCursor.close(); } } File f = new File(audioFile); if (f.exists()) { f.delete(); } return count; }
From source file:org.odk.collect.android.utilities.MediaUtils.java
public static final int deleteVideoFileFromMediaProvider(String videoFile) { ContentResolver cr = Collect.getInstance().getContentResolver(); // video//from www .j a v a 2 s. c om int count = 0; Cursor videoCursor = null; try { String select = Video.Media.DATA + "=?"; String[] selectArgs = { videoFile }; String[] projection = { Video.VideoColumns._ID }; videoCursor = cr.query(android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, select, selectArgs, null); if (videoCursor.getCount() > 0) { videoCursor.moveToFirst(); List<Uri> videoToDelete = new ArrayList<Uri>(); do { String id = videoCursor.getString(videoCursor.getColumnIndex(Video.VideoColumns._ID)); videoToDelete.add( Uri.withAppendedPath(android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id)); } while (videoCursor.moveToNext()); for (Uri uri : videoToDelete) { Log.i(t, "attempting to delete: " + uri); count += cr.delete(uri, null, null); } } } catch (Exception e) { Log.e(t, e.toString()); } finally { if (videoCursor != null) { videoCursor.close(); } } File f = new File(videoFile); if (f.exists()) { f.delete(); } return count; }
From source file:com.bangz.smartmute.services.LocationMuteService.java
private void handleDeleteGeofences(long[] ids) { LogUtils.LOGD(TAG, "Handling delete geofences..."); List<String> removeids = new ArrayList<String>(); for (long id : ids) { removeids.add(String.valueOf(id)); }//ww w. java 2 s .c o m ConnectionResult cr = mGoogleApiClient.blockingConnect(); if (cr.isSuccess() == false) { LogUtils.LOGD(TAG, "GoogleApiClient.blockconnect failed! message: " + cr.toString()); return; } Status result = LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, removeids).await(); if (result.isSuccess()) { LogUtils.LOGD(TAG, "Delete geofences successful."); } else { LogUtils.LOGD(TAG, "Delete geofences fail. message:" + result.getStatusMessage()); } mGoogleApiClient.disconnect(); // now delete these records from database ; ContentResolver contentResolver = getContentResolver(); String args = TextUtils.join(", ", removeids); String where = String.format("%s IN (%s)", RulesColumns._ID, args); contentResolver.delete(RulesColumns.CONTENT_URI, where, null); }
From source file:com.silentcircle.contacts.calllog.ClearCallLogDialog.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override/*from w w w . j a v a 2s .c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { final ContentResolver resolver = getActivity().getContentResolver(); final OnClickListener okListener = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final ProgressDialog progressDialog = ProgressDialog.show(getActivity(), getString(R.string.clearCallLogProgress_title), "", true, false); final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { resolver.delete(ScCalls.CONTENT_URI, null, null); return null; } @Override protected void onPostExecute(Void result) { progressDialog.dismiss(); } }; // TODO: Once we have the API, we should configure this ProgressDialog // to only show up after a certain time (e.g. 150ms) progressDialog.show(); task.execute(); } }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) builder.setIconAttribute(android.R.attr.alertDialogIcon); return builder.setTitle(R.string.clearCallLogConfirmation_title) .setMessage(R.string.clearCallLogConfirmation).setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, okListener).setCancelable(true).create(); }
From source file:org.odk.collect.android.utilities.MediaUtils.java
public static final int deleteImageFileFromMediaProvider(String imageFile) { ContentResolver cr = Collect.getInstance().getContentResolver(); // images/*from w ww .j a va 2 s. c o m*/ int count = 0; Cursor imageCursor = null; try { String select = Images.Media.DATA + "=?"; String[] selectArgs = { imageFile }; String[] projection = { Images.ImageColumns._ID }; imageCursor = cr.query(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, select, selectArgs, null); if (imageCursor.getCount() > 0) { imageCursor.moveToFirst(); List<Uri> imagesToDelete = new ArrayList<Uri>(); do { String id = imageCursor.getString(imageCursor.getColumnIndex(Images.ImageColumns._ID)); imagesToDelete.add(Uri .withAppendedPath(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, id)); } while (imageCursor.moveToNext()); for (Uri uri : imagesToDelete) { Log.i(t, "attempting to delete: " + uri); count += cr.delete(uri, null, null); } } } catch (Exception e) { Log.e(t, e.toString()); } finally { if (imageCursor != null) { imageCursor.close(); } } File f = new File(imageFile); if (f.exists()) { f.delete(); } return count; }
From source file:org.odk.collect.android.utilities.MediaUtils.java
public static final int deleteAudioInFolderFromMediaProvider(File folder) { ContentResolver cr = Collect.getInstance().getContentResolver(); // audio/*from w ww . ja v a 2 s . c o m*/ int count = 0; Cursor audioCursor = null; try { String select = Audio.Media.DATA + " like ? escape '!'"; String[] selectArgs = { escapePath(folder.getAbsolutePath()) }; String[] projection = { Audio.AudioColumns._ID }; audioCursor = cr.query(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, select, selectArgs, null); if (audioCursor.getCount() > 0) { audioCursor.moveToFirst(); List<Uri> audioToDelete = new ArrayList<Uri>(); do { String id = audioCursor.getString(audioCursor.getColumnIndex(Audio.AudioColumns._ID)); audioToDelete.add( Uri.withAppendedPath(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, id)); } while (audioCursor.moveToNext()); for (Uri uri : audioToDelete) { Log.i(t, "attempting to delete: " + uri); count += cr.delete(uri, null, null); } } } catch (Exception e) { Log.e(t, e.toString()); } finally { if (audioCursor != null) { audioCursor.close(); } } return count; }
From source file:org.odk.collect.android.utilities.MediaUtils.java
public static final int deleteVideoInFolderFromMediaProvider(File folder) { ContentResolver cr = Collect.getInstance().getContentResolver(); // video/*w ww .ja va2 s . c o m*/ int count = 0; Cursor videoCursor = null; try { String select = Video.Media.DATA + " like ? escape '!'"; String[] selectArgs = { escapePath(folder.getAbsolutePath()) }; String[] projection = { Video.VideoColumns._ID }; videoCursor = cr.query(android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, select, selectArgs, null); if (videoCursor.getCount() > 0) { videoCursor.moveToFirst(); List<Uri> videoToDelete = new ArrayList<Uri>(); do { String id = videoCursor.getString(videoCursor.getColumnIndex(Video.VideoColumns._ID)); videoToDelete.add( Uri.withAppendedPath(android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id)); } while (videoCursor.moveToNext()); for (Uri uri : videoToDelete) { Log.i(t, "attempting to delete: " + uri); count += cr.delete(uri, null, null); } } } catch (Exception e) { Log.e(t, e.toString()); } finally { if (videoCursor != null) { videoCursor.close(); } } return count; }