List of usage examples for android.content ContentUris withAppendedId
public static Uri withAppendedId(Uri contentUri, long id)
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
@SuppressLint("NewApi") public static String getPath(final Uri uri) { try {// ww w.ja v a2 s . c o m final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; if (isKitKat && DocumentsContract.isDocumentUri(ApplicationLoader.applicationContext, uri)) { if (isExternalStorageDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; if ("primary".equalsIgnoreCase(type)) { return Environment.getExternalStorageDirectory() + "/" + split[1]; } } else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); final Uri contentUri = ContentUris .withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); return getDataColumn(ApplicationLoader.applicationContext, contentUri, null, null); } else if (isMediaDocument(uri)) { final String docId = DocumentsContract.getDocumentId(uri); final String[] split = docId.split(":"); final String type = split[0]; Uri contentUri = null; switch (type) { case "image": contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; break; case "video": contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; break; case "audio": contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; break; } final String selection = "_id=?"; final String[] selectionArgs = new String[] { split[1] }; return getDataColumn(ApplicationLoader.applicationContext, contentUri, selection, selectionArgs); } } else if ("content".equalsIgnoreCase(uri.getScheme())) { return getDataColumn(ApplicationLoader.applicationContext, uri, null, null); } else if ("file".equalsIgnoreCase(uri.getScheme())) { return uri.getPath(); } } catch (Exception e) { FileLog.e(e); } return null; }
From source file:com.markupartist.sthlmtraveling.RoutesActivity.java
/** * Updates the journey history./*w w w. j av a2 s .com*/ */ private void updateJourneyHistory() { // TODO: Move to async task. String json; try { json = mJourneyQuery.toJson(false).toString(); } catch (JSONException e) { Log.e(TAG, "Failed to convert journey to a json document."); return; } String[] projection = new String[] { Journeys._ID, // 0 Journeys.JOURNEY_DATA, // 1 Journeys.STARRED, // 2 }; String selection = Journeys.JOURNEY_DATA + " = ?"; Cursor cursor = managedQuery(Journeys.CONTENT_URI, projection, selection, new String[] { json }, null); startManagingCursor(cursor); ContentValues values = new ContentValues(); Uri journeyUri; if (cursor.getCount() > 0) { cursor.moveToFirst(); journeyUri = ContentUris.withAppendedId(Journeys.CONTENT_URI, cursor.getInt(0)); getContentResolver().update(journeyUri, values, null, null); } else { // Not sure if this is the best way to do it, but the lack limit and // offset in on a content provider leaves us to fetch all and iterate. values.put(Journeys.JOURNEY_DATA, json); journeyUri = getContentResolver().insert(Journeys.CONTENT_URI, values); Cursor notStarredCursor = managedQuery(Journeys.CONTENT_URI, projection, Journeys.STARRED + " = ? OR " + Journeys.STARRED + " IS NULL", new String[] { "0" }, Journeys.DEFAULT_SORT_ORDER); startManagingCursor(notStarredCursor); // +1 because the position is zero-based. if (notStarredCursor.moveToPosition(Journeys.DEFAULT_HISTORY_SIZE + 1)) { do { Uri deleteUri = ContentUris.withAppendedId(Journeys.CONTENT_URI, notStarredCursor.getInt(0)); getContentResolver().delete(deleteUri, null, null); } while (notStarredCursor.moveToNext()); } stopManagingCursor(notStarredCursor); } stopManagingCursor(cursor); // TODO: Store created id and work on that while toggling if starred or not. }
From source file:com.android.contacts.quickcontact.QuickContactActivity.java
private void processIntent(Intent intent) { if (intent == null) { finish();//from w w w . j a v a 2 s . c om return; } Uri lookupUri = intent.getData(); // Check to see whether it comes from the old version. if (lookupUri != null && LEGACY_AUTHORITY.equals(lookupUri.getAuthority())) { final long rawContactId = ContentUris.parseId(lookupUri); lookupUri = RawContacts.getContactLookupUri(getContentResolver(), ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId)); } mExtraMode = getIntent().getIntExtra(QuickContact.EXTRA_MODE, QuickContact.MODE_LARGE); mExtraPrioritizedMimeType = getIntent().getStringExtra(QuickContact.EXTRA_PRIORITIZED_MIMETYPE); final Uri oldLookupUri = mLookupUri; if (lookupUri == null) { finish(); return; } mLookupUri = lookupUri; mExcludeMimes = intent.getStringArrayExtra(QuickContact.EXTRA_EXCLUDE_MIMES); if (oldLookupUri == null) { mContactLoader = (ContactLoader) getLoaderManager().initLoader(LOADER_CONTACT_ID, null, mLoaderContactCallbacks); } else if (oldLookupUri != mLookupUri) { // After copying a directory contact, the contact URI changes. Therefore, // we need to reload the new contact. destroyInteractionLoaders(); mContactLoader = (ContactLoader) (Loader<?>) getLoaderManager().getLoader(LOADER_CONTACT_ID); mContactLoader.setLookupUri(mLookupUri); mCachedCp2DataCardModel = null; } mContactLoader.forceLoad(); NfcHandler.register(this, mLookupUri); }
From source file:com.android.contacts.ContactSaveService.java
private void clearPrimary(Intent intent) { long dataId = intent.getLongExtra(EXTRA_DATA_ID, -1); if (dataId == -1) { Log.e(TAG, "Invalid arguments for clearPrimary request"); return;//from w w w . j a v a 2 s .c o m } // Update the primary values in the data record. ContentValues values = new ContentValues(1); values.put(Data.IS_SUPER_PRIMARY, 0); values.put(Data.IS_PRIMARY, 0); getContentResolver().update(ContentUris.withAppendedId(Data.CONTENT_URI, dataId), values, null, null); }
From source file:com.android.exchange.adapter.EmailSyncAdapter.java
private void addCleanupOps(ArrayList<ContentProviderOperation> ops) { // If we've sent local deletions, clear out the deleted table for (Long id : mDeletedIdList) { ops.add(ContentProviderOperation.newDelete(ContentUris.withAppendedId(Message.DELETED_CONTENT_URI, id)) .build());//from ww w . j a va 2s . c om } // And same with the updates for (Long id : mUpdatedIdList) { ops.add(ContentProviderOperation.newDelete(ContentUris.withAppendedId(Message.UPDATED_CONTENT_URI, id)) .build()); } }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private Uri getContactUriForEmail(String emailAddress) { Cursor cursor = SqliteWrapper.query(this, getContentResolver(), Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(emailAddress)), new String[] { Email.CONTACT_ID, Contacts.DISPLAY_NAME }, null, null, null); if (cursor != null) { try {/*from w ww . j a v a 2 s .c om*/ while (cursor.moveToNext()) { String name = cursor.getString(1); if (!TextUtils.isEmpty(name)) { return ContentUris.withAppendedId(Contacts.CONTENT_URI, cursor.getLong(0)); } } } finally { cursor.close(); } } return null; }
From source file:com.android.contacts.ContactSaveService.java
private void deleteMultipleContacts(Intent intent) { final long[] contactIds = intent.getLongArrayExtra(EXTRA_CONTACT_IDS); if (contactIds == null) { Log.e(TAG, "Invalid arguments for deleteMultipleContacts request"); return;/* w w w. ja v a2s . c o m*/ } for (long contactId : contactIds) { final Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId); getContentResolver().delete(contactUri, null, null); } final String[] names = intent.getStringArrayExtra(ContactSaveService.EXTRA_DISPLAY_NAME_ARRAY); final String deleteToastMessage; if (contactIds.length != names.length || names.length == 0) { deleteToastMessage = getResources().getQuantityString(R.plurals.contacts_deleted_toast, contactIds.length); } else if (names.length == 1) { deleteToastMessage = getResources().getString(R.string.contacts_deleted_one_named_toast, names); } else if (names.length == 2) { deleteToastMessage = getResources().getString(R.string.contacts_deleted_two_named_toast, names); } else { deleteToastMessage = getResources().getString(R.string.contacts_deleted_many_named_toast, names); } mMainHandler.post(new Runnable() { @Override public void run() { Toast.makeText(ContactSaveService.this, deleteToastMessage, Toast.LENGTH_LONG).show(); } }); }
From source file:com.android.calendar.AllInOneActivity.java
@Override public void handleEvent(EventInfo event) { long displayTime = -1; if (event.eventType == EventType.GO_TO) { if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) { mBackToPreviousView = true;/* w ww .j av a2 s .c om*/ } else if (event.viewType != mController.getPreviousViewType() && event.viewType != ViewType.EDIT) { // Clear the flag is change to a different view type mBackToPreviousView = false; } setMainPane(null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false); if (mSearchView != null) { mSearchView.clearFocus(); } if (mShowCalendarControls) { int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? mControlsAnimateWidth : mControlsAnimateHeight; boolean noControlsView = event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA; if (mControlsMenu != null) { mControlsMenu.setVisible(!noControlsView); mControlsMenu.setEnabled(!noControlsView); } if (noControlsView || mHideControls) { // hide minimonth and calendar frag mShowSideViews = false; if (!mHideControls) { final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 0, animationSize); slideAnimation.addListener(mSlideAnimationDoneListener); slideAnimation.setDuration(mCalendarControlsAnimationTime); ObjectAnimator.setFrameDelay(0); slideAnimation.start(); } else { mMiniMonth.setVisibility(View.GONE); mCalendarsList.setVisibility(View.GONE); mMiniMonthContainer.setVisibility(View.GONE); } } else { // show minimonth and calendar frag mShowSideViews = true; mMiniMonth.setVisibility(View.VISIBLE); mCalendarsList.setVisibility(View.VISIBLE); mMiniMonthContainer.setVisibility(View.VISIBLE); if (!mHideControls && (mController.getPreviousViewType() == ViewType.MONTH || mController.getPreviousViewType() == ViewType.AGENDA)) { final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", animationSize, 0); slideAnimation.setDuration(mCalendarControlsAnimationTime); ObjectAnimator.setFrameDelay(0); slideAnimation.start(); } } } displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true) : event.startTime.toMillis(true); if (!mIsTabletConfig) { refreshActionbarTitle(displayTime); } } else if (event.eventType == EventType.VIEW_EVENT) { // If in Agenda view and "show_event_details_with_agenda" is "true", // do not create the event info fragment here, it will be created by the Agenda // fragment if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) { if (event.startTime != null && event.endTime != null) { // Event is all day , adjust the goto time to local time if (event.isAllDay()) { Utils.convertAlldayUtcToLocal(event.startTime, event.startTime.toMillis(false), mTimeZone); Utils.convertAlldayUtcToLocal(event.endTime, event.endTime.toMillis(false), mTimeZone); } mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime, event.selectedTime, event.id, ViewType.AGENDA, CalendarController.EXTRA_GOTO_TIME, null, null); } else if (event.selectedTime != null) { mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, event.id, ViewType.AGENDA); } } else { // TODO Fix the temp hack below: && mCurrentView != // ViewType.AGENDA if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) { mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, -1, ViewType.CURRENT); } int response = event.getResponse(); if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda) || ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK) || mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)) { // start event info as activity Intent intent = new Intent(Intent.ACTION_VIEW); Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id); intent.setData(eventUri); intent.setClass(this, EventInfoActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false)); intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false)); intent.putExtra(ATTENDEE_STATUS, response); startActivity(intent); } else { // start event info as a dialog EventInfoFragment fragment = new EventInfoFragment(this, event.id, event.startTime.toMillis(false), event.endTime.toMillis(false), response, true, EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */); fragment.setDialogParams(event.x, event.y, mActionBar.getHeight()); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); // if we have an old popup replace it Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG); if (fOld != null && fOld.isAdded()) { ft.remove(fOld); } ft.add(fragment, EVENT_INFO_FRAGMENT_TAG); ft.commit(); } } displayTime = event.startTime.toMillis(true); } else if (event.eventType == EventType.UPDATE_TITLE) { setTitleInActionBar(event); if (!mIsTabletConfig) { refreshActionbarTitle(mController.getTime()); } } updateSecondaryTitleFields(displayTime); }
From source file:com.chen.emailsync.SyncManager.java
public void setMailboxSyncStatus(long id, int status) { ContentValues values = new ContentValues(); values.put(Mailbox.UI_SYNC_STATUS, status); mResolver.update(ContentUris.withAppendedId(Mailbox.CONTENT_URI, id), values, null, null); }
From source file:com.chen.emailsync.SyncManager.java
public void setMailboxLastSyncResult(long id, int result) { ContentValues values = new ContentValues(); values.put(Mailbox.UI_LAST_SYNC_RESULT, result); mResolver.update(ContentUris.withAppendedId(Mailbox.CONTENT_URI, id), values, null, null); }