List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.grokkingandroid.sampleapp.samples.data.contentprovider.lentitems.CPSampleActivity.java
public void deleteItem(final long itemId) { final ContentResolver resolver = getContentResolver(); new Thread(new Runnable() { // for as long as this runs the activity will not be GCed public void run() { Uri delUri = ContentUris.withAppendedId(Items.CONTENT_URI, itemId); int resCount = resolver.delete(delUri, null, null); if (resCount == 0) { // do s.th. useful }/*from w w w . j a va 2s . c o m*/ } }).start(); getSupportFragmentManager().popBackStack(); }
From source file:cn.code.notes.gtask.data.SqlConn.java
public void commit(long noteId, boolean validateVersion, long version) { if (mIsCreate) { if (mId == INVALID_ID && mDiffDataValues.containsKey(ConnectColumns.NOTE_ID)) { mDiffDataValues.remove(ConnectColumns.NOTE_ID); }/* w w w. j a va2 s . c o m*/ mDiffDataValues.put(DataColumns.NOTE_ID, noteId); Uri uri = mContentResolver.insert(Notes.CONTENT_CONN_URI, mDiffDataValues); try { mId = Long.valueOf(uri.getPathSegments().get(1)); } catch (NumberFormatException e) { Log.e(TAG, "Get note id error :" + e.toString()); throw new ActionFailureException("create note failed"); } } else { if (mDiffDataValues.size() > 0) { int result = 0; if (!validateVersion) { result = mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_CONN_URI, mId), mDiffDataValues, null, null); } else { result = mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_CONN_URI, mId), mDiffDataValues, " ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE + " WHERE " + NoteColumns.VERSION + "=?)", new String[] { String.valueOf(noteId), String.valueOf(version) }); } if (result == 0) { Log.w(TAG, "there is no update. maybe user updates note when syncing"); } } } mDiffDataValues.clear(); mIsCreate = false; }
From source file:com.adampash.contactSearch.ContactsSearchModule.java
@Kroll.method private TiBlob fetchThumbnail(int thumbnailId) { ContentResolver contentResolver = appContext.getContentResolver(); String[] PHOTO_BITMAP_PROJECTION = new String[] { ContactsContract.CommonDataKinds.Photo.PHOTO }; Uri uri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, thumbnailId); Cursor cursor = contentResolver.query(uri, PHOTO_BITMAP_PROJECTION, null, null, null); try {// w w w .j av a2 s . c om Bitmap thumbnail = null; if (cursor.moveToFirst()) { byte[] thumbnailBytes = cursor.getBlob(0); if (thumbnailBytes != null) { thumbnail = BitmapFactory.decodeByteArray(thumbnailBytes, 0, thumbnailBytes.length); } } /* return thumbnail; */ return TiBlob.blobFromImage(thumbnail); } finally { cursor.close(); } }
From source file:com.smarthome.deskclock.Alarms.java
/** * Removes an existing Alarm. If this alarm is snoozing, disables * snooze. Sets next alert./*w w w . j a v a2 s . c om*/ */ public static void deleteAlarm(Context context, int alarmId) { if (alarmId == -1) return; ContentResolver contentResolver = context.getContentResolver(); /* If alarm is snoozing, lose it */ disableSnoozeAlert(context, alarmId); Uri uri = ContentUris.withAppendedId(Alarm.Columns.CONTENT_URI, alarmId); contentResolver.delete(uri, "", null); setNextAlert(context); // postAlarmId(context,alarm); }
From source file:com.andrew.apollo.utils.MusicUtils.java
public static int deletePlaylist(FragmentActivity activity, long playlistId) { if (activity.getContentResolver() == null) { return 0; }//from w ww . ja va2 s. c o m final Uri mUri = ContentUris.withAppendedId(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, playlistId); int deleted = activity.getContentResolver().delete(mUri, null, null); return deleted; }
From source file:com.google.android.demos.jamendo.app.ArtistGalleryActivity.java
/** * {@inheritDoc}/*from w w w.ja v a 2 s . c o m*/ */ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == parent.getSelectedItemPosition()) { Uri uri = ContentUris.withAppendedId(Artists.CONTENT_URI, id); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }
From source file:com.codebutler.farebot.fragments.CardsFragment.java
@Override public boolean onContextItemSelected(android.view.MenuItem item) { if (item.getItemId() == R.id.delete_card) { long id = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).id; Uri uri = ContentUris.withAppendedId(CardProvider.CONTENT_URI_CARD, id); getActivity().getContentResolver().delete(uri, null, null); return true; }/*ww w. j av a2 s . c o m*/ return false; }
From source file:com.google.android.demos.jamendo.app.AlbumGalleryActivity.java
/** * {@inheritDoc}//from www . j a v a 2 s .c om */ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == parent.getSelectedItemPosition()) { Uri uri = ContentUris.withAppendedId(Albums.CONTENT_URI, id); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }
From source file:com.ksk.droidbatterybooster.provider.TimeSchedule.java
public static void deleteTimeSchedule(Context context, long scheduleId) { if (scheduleId == -1) return;//from w w w . ja v a 2 s.c om ContentResolver contentResolver = context.getContentResolver(); Uri uri = ContentUris.withAppendedId(CONTENT_URI, scheduleId); contentResolver.delete(uri, "", null); setNextAction(context); }
From source file:com.example.android.notepad.NotesList.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); //final boolean haveItems = getListAdapter().getCount() > 0; boolean haveItems = true; // If there are any notes in the list (which implies that one of // them is selected), then we need to generate the actions that // can be performed on the current selection. This will be a combination // of our own specific actions along with any extensions that can be // found.//from w w w . j a v a2s. co m if (haveItems) { // This is the selected item. Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId()); // Build menu... always starts with the EDIT action... Intent[] specifics = new Intent[1]; specifics[0] = new Intent(Intent.ACTION_EDIT, uri); MenuItem[] items = new MenuItem[1]; // ... is followed by whatever other actions are available... Intent intent = new Intent(null, uri); intent.addCategory(Intent.CATEGORY_ALTERNATIVE); menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items); // Give a shortcut to the edit action. if (items[0] != null) { items[0].setShortcut('1', 'e'); } } else { menu.removeGroup(Menu.CATEGORY_ALTERNATIVE); } return true; }