List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:at.bitfire.davdroid.mirakel.resource.LocalCalendar.java
@Override public void setCTag(String cTag) throws LocalStorageException { ContentValues values = new ContentValues(1); values.put(COLLECTION_COLUMN_CTAG, cTag); try {/*from w w w . jav a 2 s . c om*/ providerClient.update(ContentUris.withAppendedId(calendarsURI(), id), values, null, null); } catch (RemoteException e) { throw new LocalStorageException(e); } }
From source file:cochrane343.journal.MainActivity.java
@Override public void onDeleteExpense(final long expenseId) { final Uri uri = ContentUris.withAppendedId(Expense.EXPENSES_URI, expenseId); getContentResolver().delete(uri, null, null); }
From source file:at.bitfire.ical4android.AndroidCalendar.java
public Uri calendarSyncURI() { return syncAdapterURI(ContentUris.withAppendedId(Calendars.CONTENT_URI, id)); }
From source file:com.bangz.shotrecorder.MainActivity.java
@Override public void remove(int which) { DragSortListView listView = (DragSortListView) findViewById(R.id.listRecords); long id = listView.getItemIdAtPosition(which); Uri uri = ContentUris.withAppendedId(getIntent().getData(), id); getContentResolver().delete(uri, null, null); }
From source file:com.kyakujin.android.tagnotepad.ui.TagListFragment.java
@Override public boolean onContextItemSelected(android.view.MenuItem item) { AdapterView.AdapterContextMenuInfo info; try {// w w w. java 2s . c o m info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(TAG, "bad AdapterContextMenuInfo", e); return false; } mCurrentTag = ContentUris.withAppendedId(Tags.CONTENT_URI, info.id); switch (item.getItemId()) { case R.id.context_delete: AlertDialog dlg = new AlertDialog.Builder(getActivity()).setTitle(R.string.alert_title_delete) .setIcon(android.R.drawable.ic_dialog_alert).setMessage(R.string.alert_message_delete_tag) .setPositiveButton("YES", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getActivity().getContentResolver().delete(mCurrentTag, null, null); // mapping? String where = Mapping.TAGID + " = " + Tags.getId(mCurrentTag); getActivity().getContentResolver().delete(Mapping.CONTENT_URI, where, null); } }).setNegativeButton("NO", null).setInverseBackgroundForced(true).create(); dlg.show(); return true; case R.id.context_edit: Bundle bundle = new Bundle(); bundle.putString("selectedTagName", mTagName); bundle.putString("selectedTagUri", mCurrentTag.toString()); FragmentManager manager = getActivity().getSupportFragmentManager(); TagDialogEditFragment fragment = TagDialogEditFragment.newInstance(); fragment.setArguments(bundle); fragment.show(manager, Config.TAG_TAGDIALOGEDIT_FRAGM); mCurrentTag = null; mTagName = null; return true; default: return super.onContextItemSelected(item); } }
From source file:com.ecoplayer.beta.MusicService.java
public Uri getUriFromSong(Song song) { return ContentUris.withAppendedId(android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, song.getId()); }
From source file:com.ev.contactsmultipicker.ContactListFragment.java
private Bitmap retrieveContactPhoto(String contactID) { Context context = getActivity(); Bitmap photo = null;/* ww w . j a va 2 s. com*/ try { InputStream inputStream = ContactsContract.Contacts.openContactPhotoInputStream( context.getContentResolver(), ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, new Long(contactID))); if (inputStream != null) { photo = BitmapFactory.decodeStream(inputStream); //ImageView imageView = (ImageView) findViewById(R.id.img_contact); //imageView.setImageBitmap(photo); inputStream.close(); } } catch (IOException e) { e.printStackTrace(); } return photo; }
From source file:com.deliciousdroid.platform.ContactManager.java
/** * Deletes a contact from the platform contacts provider. * // w w w. j ava 2s . c om * @param context the Authenticator Activity context * @param rawContactId the unique Id for this rawContact in contacts * provider */ private static void deleteContact(Context context, long rawContactId, BatchOperation batchOperation) { batchOperation.add(ContactOperations .newDeleteCpo(ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId), true).build()); }
From source file:cn.suishen.email.LegacyConversions.java
/** * Add a single attachment part to the message * * This will skip adding attachments if they are already found in the attachments table. * The heuristic for this will fail (false-positive) if two identical attachments are * included in a single POP3 message./*from ww w . jav a 2 s . com*/ * TODO: Fix that, by (elsewhere) simulating an mLocation value based on the attachments * position within the list of multipart/mixed elements. This would make every POP3 attachment * unique, and might also simplify the code (since we could just look at the positions, and * ignore the filename, etc.) * * TODO: Take a closer look at encoding and deal with it if necessary. * * @param context a context for file operations * @param localMessage the attachments will be built against this message * @param part a single attachment part from POP or IMAP * @throws IOException */ private static void addOneAttachment(Context context, EmailContent.Message localMessage, Part part) throws MessagingException, IOException { Attachment localAttachment = new Attachment(); // Transfer fields from mime format to provider format String contentType = MimeUtility.unfoldAndDecode(part.getContentType()); String name = MimeUtility.getHeaderParameter(contentType, "name"); if (name == null) { String contentDisposition = MimeUtility.unfoldAndDecode(part.getDisposition()); name = MimeUtility.getHeaderParameter(contentDisposition, "filename"); } // Incoming attachment: Try to pull size from disposition (if not downloaded yet) long size = 0; String disposition = part.getDisposition(); if (disposition != null) { String s = MimeUtility.getHeaderParameter(disposition, "size"); if (s != null) { size = Long.parseLong(s); } } // Get partId for unloaded IMAP attachments (if any) // This is only provided (and used) when we have structure but not the actual attachment String[] partIds = part.getHeader(MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA); String partId = partIds != null ? partIds[0] : null; localAttachment.mFileName = name; localAttachment.mMimeType = part.getMimeType(); localAttachment.mSize = size; // May be reset below if file handled localAttachment.mContentId = part.getContentId(); localAttachment.mContentUri = null; // Will be rewritten by saveAttachmentBody localAttachment.mMessageKey = localMessage.mId; localAttachment.mLocation = partId; localAttachment.mEncoding = "B"; // TODO - convert other known encodings localAttachment.mAccountKey = localMessage.mAccountKey; if (DEBUG_ATTACHMENTS) { Log.d(Logging.LOG_TAG, "Add attachment " + localAttachment); } // To prevent duplication - do we already have a matching attachment? // The fields we'll check for equality are: // mFileName, mMimeType, mContentId, mMessageKey, mLocation // NOTE: This will false-positive if you attach the exact same file, twice, to a POP3 // message. We can live with that - you'll get one of the copies. Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId); Cursor cursor = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null, null, null); boolean attachmentFoundInDb = false; try { while (cursor.moveToNext()) { Attachment dbAttachment = new Attachment(); dbAttachment.restore(cursor); // We test each of the fields here (instead of in SQL) because they may be // null, or may be strings. if (stringNotEqual(dbAttachment.mFileName, localAttachment.mFileName)) continue; if (stringNotEqual(dbAttachment.mMimeType, localAttachment.mMimeType)) continue; if (stringNotEqual(dbAttachment.mContentId, localAttachment.mContentId)) continue; if (stringNotEqual(dbAttachment.mLocation, localAttachment.mLocation)) continue; // We found a match, so use the existing attachment id, and stop looking/looping attachmentFoundInDb = true; localAttachment.mId = dbAttachment.mId; if (DEBUG_ATTACHMENTS) { Log.d(Logging.LOG_TAG, "Skipped, found db attachment " + dbAttachment); } break; } } finally { cursor.close(); } // Save the attachment (so far) in order to obtain an id if (!attachmentFoundInDb) { localAttachment.save(context); } // If an attachment body was actually provided, we need to write the file now saveAttachmentBody(context, part, localAttachment, localMessage.mAccountKey); if (localMessage.mAttachments == null) { localMessage.mAttachments = new ArrayList<Attachment>(); } localMessage.mAttachments.add(localAttachment); localMessage.mFlagAttachment = true; }
From source file:com.ternup.caddisfly.fragment.DetailsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_sendResult: if (NetworkUtils.checkInternetConnection(mContext)) { if (progressDialog == null) { progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage(getString(R.string.sending)); progressDialog.setCancelable(false); }/*from w ww .j a v a2 s . co m*/ progressDialog.show(); postResult(mFolderName); } return true; case R.id.menu_delete: AlertUtils.askQuestion(getActivity(), R.string.delete, R.string.selectedWillBeDeleted, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { FileUtils.deleteFolder(getActivity(), mLocationId, mFolderName); Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); double value = 0; int counter = 0; while (value != -1) { String key = String.format(getString(R.string.resultValueKey), mTestTypeId, mId, counter); if (PreferencesUtils.contains(mContext, key)) { PreferencesUtils.removeKey(mContext, key); } else { value = -1; } counter++; } goBack(); } }, null); return true; default: return super.onOptionsItemSelected(item); } }