List of usage examples for android.net Uri withAppendedPath
public static Uri withAppendedPath(Uri baseUri, String pathSegment)
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * ???// www. ja v a 2 s. c om * @param messageType ?MMS,SMS,Email * @param folderType * @return ?? */ private int getQuantities(String messageType, String folderType) { //TODO:???Email? if (null == folderType) {// folderTypenull? folderType = FOLDERTYPE_DRAFT; } folderType = folderType.toLowerCase(); Uri uri = Uri.withAppendedPath(mSMSContentUri, folderType); //TODO:?SIM?? final int count = getRecordCount(uri, null, null); return count; }
From source file:com.ichi2.anki.tests.ContentProviderTest.java
/** * Test that a query for all the notes added in setup() looks correct *///from w w w. j a v a 2s . co m public void testQueryNoteIds() { final ContentResolver cr = getContext().getContentResolver(); // Query all available notes final Cursor allNotesCursor = cr.query(FlashCardsContract.Note.CONTENT_URI, null, "tag:" + TEST_TAG, null, null); assertNotNull(allNotesCursor); try { assertEquals("Check number of results", mCreatedNotes.size(), allNotesCursor.getCount()); while (allNotesCursor.moveToNext()) { // Check that it's possible to leave out columns from the projection for (int i = 0; i < FlashCardsContract.Note.DEFAULT_PROJECTION.length; i++) { String[] projection = removeFromProjection(FlashCardsContract.Note.DEFAULT_PROJECTION, i); String noteId = allNotesCursor .getString(allNotesCursor.getColumnIndex(FlashCardsContract.Note._ID)); Uri noteUri = Uri.withAppendedPath(FlashCardsContract.Note.CONTENT_URI, noteId); final Cursor singleNoteCursor = cr.query(noteUri, projection, null, null, null); assertNotNull("Check that there is a valid cursor for detail data", singleNoteCursor); try { assertEquals("Check that there is exactly one result", 1, singleNoteCursor.getCount()); assertTrue("Move to beginning of cursor after querying for detail data", singleNoteCursor.moveToFirst()); // Check columns assertEquals("Check column count", projection.length, singleNoteCursor.getColumnCount()); for (int j = 0; j < projection.length; j++) { assertEquals("Check column name " + j, projection[j], singleNoteCursor.getColumnName(j)); } } finally { singleNoteCursor.close(); } } } } finally { allNotesCursor.close(); } }
From source file:org.openbmap.activities.WifiListContainer.java
@Override public final Loader<Cursor> onCreateLoader(final int arg0, final Bundle arg1) { final String[] projection = { Schema.COL_ID, Schema.COL_BSSID, Schema.COL_SSID, "MAX(" + Schema.COL_LEVEL + ")", //Schema.COL_IS_NEW_WIFI, Schema.COL_KNOWN_WIFI, Schema.COL_CAPABILITIES }; mCursorLoader = new CursorLoader(getActivity().getBaseContext(), ContentUris.withAppendedId(Uri.withAppendedPath(RadioBeaconContentProvider.CONTENT_URI_WIFI, RadioBeaconContentProvider.CONTENT_URI_OVERVIEW_SUFFIX), mSession), projection, mSelection, mSelectionArgs, mSortColumn + mSortOrder); return mCursorLoader; }
From source file:org.odk.collect.android.utilities.MediaUtils.java
public static final Uri getVideoUriFromMediaProvider(String videoFile) { String selection = Video.VideoColumns.DATA + "=?"; String[] selectArgs = { videoFile }; String[] projection = { Video.VideoColumns._ID }; Cursor c = null;/*from ww w. ja va 2s.c om*/ try { c = Collect.getInstance().getContentResolver().query( android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI, projection, selection, selectArgs, null); if (c.getCount() > 0) { c.moveToFirst(); String id = c.getString(c.getColumnIndex(Video.VideoColumns._ID)); return Uri.withAppendedPath(android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI, id); } return null; } finally { if (c != null) { c.close(); } } }
From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { if (id == ContactsQuery.QUERY_ID) { Uri contentUri;//from w w w .j a v a 2 s .c o m if (searchString == null) { contentUri = ContactsQuery.CONTENT_URI; } else { contentUri = Uri.withAppendedPath(ContactsQuery.FILTER_URI, Uri.encode(searchString)); } return new CursorLoader(getActivity(), contentUri, ContactsQuery.PROJECTION, ContactsQuery.SELECTION, null, ContactsQuery.SORT_ORDER); } LogUtil.e(TAG, "onCreateLoader - incorrect ID provided (" + id + ")"); return null; }
From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java
/** * Insert new monitor into Monitor table, automatically generating monitor id. * /*w w w . java 2 s . c om*/ * @param offsettime time offset to apply to data table times to acquire time * from epoch, in milliseconds * @return new monitor id * * @see MonitorTable */ public synchronized int insertMonitor(long offsettime) { if (DebugLog.DEBUG) Log.d(TAG, "CimonDatabaseAdapter.insertMonitor - insert into Monitor table: time-" + offsettime); ContentValues values = new ContentValues(); values.put(MonitorTable.COLUMN_TIME_OFFSET, offsettime); values.put(MonitorTable.COLUMN_ENDTIME, 0); long rowid = database.insert(MonitorTable.TABLE_MONITOR, null, values); if (rowid >= 0) { Uri uri = Uri.withAppendedPath(CimonContentProvider.MONITOR_URI, String.valueOf(rowid)); context.getContentResolver().notifyChange(uri, null); } return (int) rowid; }
From source file:com.android.julia.todolist.ui.MainActivity.java
/** * This method is called after the user presses 'Save' button in EditTaskDialogFragment. * Edited data of the task puts into ContentResolver, then database updates, and then * restarts the loader to re-query the underlying data for any changes. *//* w ww . j a v a 2 s .c o m*/ @Override public void onFinishEditTaskDialog(int position, String description, int priority) { // Update new task data via a ContentResolver. // Create new empty ContentValues object. ContentValues contentValues = new ContentValues(); // Put the task description and selected priority into the ContentValues contentValues.put(TaskContract.TaskEntry.COLUMN_DESCRIPTION, description); contentValues.put(TaskContract.TaskEntry.COLUMN_PRIORITY, priority); // Create uri path with id of edited task Uri uri = Uri.withAppendedPath(TaskContract.TaskEntry.CONTENT_URI, Integer.toString(position)); // Update the content values via a ContentResolver getContentResolver().update(uri, contentValues, null, null); // Restart the loader to re-query for all tasks after an editing getSupportLoaderManager().restartLoader(TASK_LOADER_ID, null, MainActivity.this); }
From source file:com.noshufou.android.su.AppDetailsFragment.java
public void forget(View view) { if (!mReady) { return;//from w ww . j a va 2 s.c o m } ContentResolver cr = getActivity().getContentResolver(); Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(mShownIndex)); cr.delete(uri, null, null); closeDetails(); }
From source file:org.pixmob.feedme.ui.EntriesFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); getListView().setItemChecked(position, true); final Integer entryId = (Integer) v.getTag(EntryCursorAdapter.ID_TAG); final Uri entryUri = Uri.withAppendedPath(Entries.CONTENT_URI, String.valueOf(entryId)); selectedEntryUri = entryUri;/*from w w w.j a v a 2s.c o m*/ final OnEntrySelectionListener listener = listenerRef != null ? listenerRef.get() : null; if (listener != null) { try { listener.onEntrySelected(entryUri); } catch (Exception e) { Log.e(TAG, "Failed to select entry: " + entryUri, e); } } }
From source file:org.codarama.haxsync.services.ContactsSyncAdapterService.java
private static void updateContactStatus(long rawContactId, String status, long timeStamp) { if (status != null && timeStamp != 0) { ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId); Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY); Cursor c = mContentResolver.query(entityUri, new String[] { RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1 }, null, null, null);/* w w w . j ava 2 s.c o m*/ try { while (c.moveToNext()) { if (!c.isNull(1)) { String mimeType = c.getString(2); if (mimeType.equals("vnd.android.cursor.item/vnd.org.codarama.haxsync.profile")) { ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(ContactsContract.StatusUpdates.CONTENT_URI); builder.withValue(ContactsContract.StatusUpdates.DATA_ID, c.getLong(1)); builder.withValue(ContactsContract.StatusUpdates.STATUS, status); builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE, "org.codarama.haxsync"); builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name); builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.icon); builder.withValue(ContactsContract.StatusUpdates.STATUS_TIMESTAMP, timeStamp); operationList.add(builder.build()); } } } } finally { c.close(); } try { mContentResolver.applyBatch(ContactsContract.AUTHORITY, operationList); } catch (RemoteException e) { Log.e("Error", e.getLocalizedMessage()); } catch (OperationApplicationException e) { Log.e("Error", e.getLocalizedMessage()); } } }