List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.android.messaging.mmslib.pdu.PduPersister.java
/** * Move a PDU object from one location to another. * * @param from Specify the PDU object to be moved. * @param to The destination location, should be one of the following: * "content://mms/inbox", "content://mms/sent", * "content://mms/drafts", "content://mms/outbox", * "content://mms/trash"./*from w w w . j a v a2s . c o m*/ * @return New Uri of the moved PDU. * @throws MmsException Error occurred while moving the message. */ public Uri move(final Uri from, final Uri to) throws MmsException { // Check whether the 'msgId' has been assigned a valid value. final long msgId = ContentUris.parseId(from); if (msgId == -1L) { throw new MmsException("Error! ID of the message: -1."); } // Get corresponding int value of destination box. final Integer msgBox = MESSAGE_BOX_MAP.get(to); if (msgBox == null) { throw new MmsException("Bad destination, must be one of " + "content://mms/inbox, content://mms/sent, " + "content://mms/drafts, content://mms/outbox, " + "content://mms/temp."); } final ContentValues values = new ContentValues(1); values.put(Mms.MESSAGE_BOX, msgBox); SqliteWrapper.update(mContext, mContentResolver, from, values, null, null); return ContentUris.withAppendedId(to, msgId); }
From source file:com.andrew.apolloMod.service.ApolloService.java
private void saveBookmarkIfNeeded() { try {//from ww w . j ava 2s . c om if (isPodcast()) { long pos = position(); long bookmark = getBookmark(); long duration = duration(); if ((pos < bookmark && (pos + 10000) > bookmark) || (pos > bookmark && (pos - 10000) < bookmark)) { // The existing bookmark is close to the current // position, so don't update it. return; } if (pos < 15000 || (pos + 10000) > duration) { // if we're near the start or end, clear the bookmark pos = 0; } // write 'pos' to the bookmark field ContentValues values = new ContentValues(); values.put(AudioColumns.BOOKMARK, pos); Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, mCursor.getLong(IDCOLIDX)); getContentResolver().update(uri, values, null, null); } } catch (SQLiteException ex) { } }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void lockMessage(MessageItem msgItem, boolean locked) { Uri uri;//from ww w . j a v a 2s. co m if ("sms".equals(msgItem.mType)) { uri = Sms.CONTENT_URI; } else { uri = Mms.CONTENT_URI; } final Uri lockUri = ContentUris.withAppendedId(uri, msgItem.mMsgId); final ContentValues values = new ContentValues(1); values.put("locked", locked ? 1 : 0); new Thread(new Runnable() { @Override public void run() { getContentResolver().update(lockUri, values, null, null); } }, "ComposeMessageActivity.lockMessage").start(); }
From source file:com.android.calendar.EventInfoFragment.java
private void updateResponse(long eventId, long attendeeId, int status) { // Update the attendee status in the attendees table. the provider // takes care of updating the self attendance status. ContentValues values = new ContentValues(); if (!TextUtils.isEmpty(mCalendarOwnerAccount)) { values.put(Attendees.ATTENDEE_EMAIL, mCalendarOwnerAccount); }//from w w w .j a v a 2s. c o m values.put(Attendees.ATTENDEE_STATUS, status); values.put(Attendees.EVENT_ID, eventId); Uri uri = ContentUris.withAppendedId(Attendees.CONTENT_URI, attendeeId); mHandler.startUpdate(mHandler.getNextToken(), null, uri, values, null, null, Utils.UNDO_DELAY); }
From source file:com.android.contacts.ContactSaveService.java
private void joinContacts(Intent intent) { long contactId1 = intent.getLongExtra(EXTRA_CONTACT_ID1, -1); long contactId2 = intent.getLongExtra(EXTRA_CONTACT_ID2, -1); // Load raw contact IDs for all raw contacts involved - currently edited and selected // in the join UIs. long rawContactIds[] = getRawContactIdsForAggregation(contactId1, contactId2); if (rawContactIds == null) { Log.e(TAG, "Invalid arguments for joinContacts request"); return;/*w w w .j a va 2 s.co m*/ } ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(); // For each pair of raw contacts, insert an aggregation exception for (int i = 0; i < rawContactIds.length; i++) { for (int j = 0; j < rawContactIds.length; j++) { if (i != j) { buildJoinContactDiff(operations, rawContactIds[i], rawContactIds[j]); } } } final ContentResolver resolver = getContentResolver(); // Use the name for contactId1 as the name for the newly aggregated contact. final Uri contactId1Uri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId1); final Uri entityUri = Uri.withAppendedPath(contactId1Uri, Contacts.Entity.CONTENT_DIRECTORY); Cursor c = resolver.query(entityUri, ContactEntityQuery.PROJECTION, ContactEntityQuery.SELECTION, null, null); if (c == null) { Log.e(TAG, "Unable to open Contacts DB cursor"); showToast(R.string.contactSavedErrorToast); return; } long dataIdToAddSuperPrimary = -1; try { if (c.moveToFirst()) { dataIdToAddSuperPrimary = c.getLong(ContactEntityQuery.DATA_ID); } } finally { c.close(); } // Mark the name from contactId1 IS_SUPER_PRIMARY to make sure that the contact // display name does not change as a result of the join. if (dataIdToAddSuperPrimary != -1) { Builder builder = ContentProviderOperation .newUpdate(ContentUris.withAppendedId(Data.CONTENT_URI, dataIdToAddSuperPrimary)); builder.withValue(Data.IS_SUPER_PRIMARY, 1); builder.withValue(Data.IS_PRIMARY, 1); operations.add(builder.build()); } // Apply all aggregation exceptions as one batch final boolean success = applyOperations(resolver, operations); final String name = queryNameOfLinkedContacts(new long[] { contactId1, contactId2 }); Intent callbackIntent = intent.getParcelableExtra(EXTRA_CALLBACK_INTENT); if (success && name != null) { if (TextUtils.isEmpty(name)) { showToast(R.string.contactsJoinedMessage); } else { showToast(R.string.contactsJoinedNamedMessage, name); } Uri uri = RawContacts.getContactLookupUri(resolver, ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactIds[0])); callbackIntent.setData(uri); LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(BROADCAST_LINK_COMPLETE)); } deliverCallback(callbackIntent); }
From source file:com.android.mms.ui.ComposeMessageActivity.java
/** * Looks to see if there are any valid parts of the attachment that can be copied to a SD card. * @param msgId//from w w w . j av a2 s . c o m */ private boolean haveSomethingToCopyToSDCard(long msgId) { PduBody body = null; try { body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId)); } catch (MmsException e) { Log.e(TAG, "haveSomethingToCopyToSDCard can't load pdu body: " + msgId); } if (body == null) { return false; } boolean result = false; int partNum = body.getPartsNum(); for (int i = 0; i < partNum; i++) { PduPart part = body.getPart(i); String type = new String(part.getContentType()); if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) { log("[CMA] haveSomethingToCopyToSDCard: part[" + i + "] contentType=" + type); } if (ContentType.isImageType(type) || ContentType.isVideoType(type) || ContentType.isAudioType(type) || DrmUtils.isDrmType(type)) { result = true; break; } } return result; }
From source file:com.android.mms.ui.ComposeMessageActivity.java
/** * Copies media from an Mms to the DrmProvider * @param msgId// ww w .j av a 2 s . c om */ private boolean saveRingtone(long msgId) { boolean result = true; PduBody body = null; try { body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId)); } catch (MmsException e) { Log.e(TAG, "copyToDrmProvider can't load pdu body: " + msgId); } if (body == null) { return false; } int partNum = body.getPartsNum(); for (int i = 0; i < partNum; i++) { PduPart part = body.getPart(i); String type = new String(part.getContentType()); if (DrmUtils.isDrmType(type)) { // All parts (but there's probably only a single one) have to be successful // for a valid result. result &= copyPart(part, Long.toHexString(msgId)); } } return result; }
From source file:com.android.calendar.EventInfoFragment.java
private void doEdit() { Context c = getActivity();//from www .j a v a 2 s .c o m // This ensures that we aren't in the process of closing and have been // unattached already if (c != null) { Uri uri = ContentUris.withAppendedId(Events.CONTENT_URI, mEventId); Intent intent = new Intent(Intent.ACTION_EDIT, uri); intent.setClass(mActivity, EditEventActivity.class); intent.putExtra(EXTRA_EVENT_BEGIN_TIME, mStartMillis); intent.putExtra(EXTRA_EVENT_END_TIME, mEndMillis); intent.putExtra(EXTRA_EVENT_ALL_DAY, mAllDay); intent.putExtra(EditEventActivity.EXTRA_EVENT_COLOR, mCurrentColor); intent.putExtra(EditEventActivity.EXTRA_EVENT_REMINDERS, EventViewUtils .reminderItemsToReminders(mReminderViews, mReminderMinuteValues, mReminderMethodValues)); intent.putExtra(EVENT_EDIT_ON_LAUNCH, true); startActivity(intent); } }
From source file:com.android.mms.ui.ComposeMessageActivity.java
/** * Returns true if any part is drm'd audio with ringtone rights. * @param msgId/*from w w w .j av a 2 s . co m*/ * @return true if one of the parts is drm'd audio with rights to save as a ringtone. */ private boolean isDrmRingtoneWithRights(long msgId) { PduBody body = null; try { body = SlideshowModel.getPduBody(this, ContentUris.withAppendedId(Mms.CONTENT_URI, msgId)); } catch (MmsException e) { Log.e(TAG, "isDrmRingtoneWithRights can't load pdu body: " + msgId); } if (body == null) { return false; } int partNum = body.getPartsNum(); for (int i = 0; i < partNum; i++) { PduPart part = body.getPart(i); String type = new String(part.getContentType()); if (DrmUtils.isDrmType(type)) { String mimeType = MmsApp.getApplication().getDrmManagerClient() .getOriginalMimeType(part.getDataUri()); if (ContentType.isAudioType(mimeType) && DrmUtils.haveRightsForAction(part.getDataUri(), DrmStore.Action.RINGTONE)) { return true; } } } return false; }