Example usage for android.net Uri withAppendedPath

List of usage examples for android.net Uri withAppendedPath

Introduction

In this page you can find the example usage for android.net Uri withAppendedPath.

Prototype

public static Uri withAppendedPath(Uri baseUri, String pathSegment) 

Source Link

Document

Creates a new Uri by appending an already-encoded path segment to a base Uri.

Usage

From source file:net.niyonkuru.koodroid.ui.PageFragment.java

@Override
public void onResume() {
    super.onResume();

    mReceiver.setReceiver(this);

    if (canSync())
        sync();//www  .  ja v  a 2s  .com
    showLoading(isSyncing());

    final ContentResolver cr = mContext.getContentResolver();
    final Uri pageChangeUri = Uri.withAppendedPath(Settings.CONTENT_URI, Settings.PAGE);
    cr.registerContentObserver(pageChangeUri, false, mPageChangeObserver);

    updateTimestamps();
}

From source file:org.trakhound.www.trakhound.device_list.GetDevices.java

public static ListItem[] get(UserConfiguration userConfig) {

    if (userConfig != null) {

        try {//from ww w .  j  ava 2 s.com

            String urlSuffix = "data/get/?" + "token=" + URLEncoder.encode(userConfig.sessionToken, "UTF-8")
                    + "&sender_id=" + URLEncoder.encode(UserManagement.getSenderId(), "UTF-8")
                    + "&command=1101"; // Get Description, Status, and Oee tables

            String url = Uri.withAppendedPath(ApiConfiguration.apiHost, urlSuffix).toString();

            String response = Requests.get(url);
            return processResponse(response);

        } catch (UnsupportedEncodingException ex) {
            Log.d("Exception", ex.getMessage());
        }
    }

    return null;
}

From source file:org.easyaccess.phonedialer.CallStateService.java

/**
 * Plays the ringtone associated with the number passed as a parameter.
 * //from  w  ww .  j a v a2 s  .  co m
 * @param number
 *            The number associated with the incoming call.
 */
void playRingtone(String number) {
    Uri queryUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));

    String[] columns = new String[] { ContactsContract.Contacts.CUSTOM_RINGTONE };

    Cursor contactsCursor = getContentResolver().query(queryUri, columns, null, null, null);

    if (contactsCursor.moveToFirst()) {
        if (contactsCursor
                .getString(contactsCursor.getColumnIndex(ContactsContract.Contacts.CUSTOM_RINGTONE)) == null) {
            // no custom ringtone has been set
            Utils.ringtone = RingtoneManager.getRingtone(getBaseContext(),
                    Settings.System.DEFAULT_RINGTONE_URI);
            Utils.ringtone.play();
        } else {
            Utils.ringtone = RingtoneManager.getRingtone(getBaseContext(), Uri.parse(contactsCursor
                    .getString(contactsCursor.getColumnIndex(ContactsContract.Contacts.CUSTOM_RINGTONE))));
            Utils.ringtone.play();
        }
    }

}

From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java

@Test
public void test_Intents() {
    // Launch activity with ACTION_SEARCH intent and then trigger new ACTION_VIEW intent

    // Launch activity
    Intent intent = getNewIntent();/*from  w  ww.  j  ava 2s. c  o  m*/
    intent.setAction(Intent.ACTION_SEARCH);
    intent.putExtra(SearchManager.QUERY, SEARCH_TEXT);
    createWithIntent(intent);
    // Verify onCreate() resulted in LoaderCallbacks object being created 
    assertThat(titleSearchResultsActivity.loaderCallbacks).isNotNull();
    // Verify LoaderManager restartLoader called with correct search term
    ArgumentCaptor<Bundle> arguments = ArgumentCaptor.forClass(Bundle.class);
    verify(loaderManager).restartLoader(eq(0), arguments.capture(),
            eq(titleSearchResultsActivity.loaderCallbacks));
    assertThat(arguments.getValue().containsKey("QUERY_TEXT_KEY"));
    assertThat(arguments.getValue().get("QUERY_TEXT_KEY")).isEqualTo(SEARCH_TEXT);
    // Verify setOnItemClickListener called on view
    verify(listView).setOnItemClickListener(isA(OnItemClickListener.class));
    // Verify Loader constructor arguments have correct details
    SuggestionCursorParameters params = new SuggestionCursorParameters(arguments.getValue(),
            ClassyFySearchEngine.LEX_CONTENT_URI, 50);
    assertThat(params.getUri())
            .isEqualTo(Uri.parse("content://au.com.cybersearch2.classyfy.ClassyFyProvider/lex/"
                    + SearchManager.SUGGEST_URI_PATH_QUERY));
    assertThat(params.getProjection()).isNull();
    assertThat(params.getSelection()).isEqualTo("word MATCH ?");
    assertThat(params.getSelectionArgs()).isEqualTo(new String[] { SEARCH_TEXT });
    assertThat(params.getSortOrder()).isNull();
    // Verify Loader callbacks in sequence onCreateLoader, onLoadFinished and onLoaderReset
    CursorLoader cursorLoader = (CursorLoader) titleSearchResultsActivity.loaderCallbacks.onCreateLoader(0,
            arguments.getValue());
    Cursor cursor = mock(Cursor.class);
    titleSearchResultsActivity.loaderCallbacks.onLoadFinished(cursorLoader, cursor);
    verify(simpleCursorAdapter).swapCursor(cursor);
    titleSearchResultsActivity.loaderCallbacks.onLoaderReset(cursorLoader);
    verify(simpleCursorAdapter).swapCursor(null);
    // Trigger new ACTION_VIEW intent and confirm MainActivity started with ACTION_VIEW intent
    intent = getNewIntent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri actionUri = Uri.withAppendedPath(ClassyFySearchEngine.CONTENT_URI, "44");
    intent.setData(actionUri);
    titleSearchResultsActivity.onNewIntent(intent);
    ShadowActivity shadowActivity = Robolectric.shadowOf(titleSearchResultsActivity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertThat(startedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(startedIntent.getData()).isEqualTo(actionUri);
    ShadowIntent shadowIntent = Robolectric.shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName())
            .isEqualTo("au.com.cybersearch2.classyfy.MainActivity");
}

From source file:com.android.contacts.common.model.ContactLoaderTest.java

public void testLoadContactWithRawContactIdUri() {
    // Use content Uris that only contain the ID but use the format used in Donut
    final Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, RAW_CONTACT_ID);
    final Uri baseUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, CONTACT_ID);
    final Uri lookupUri = ContentUris
            .withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, LOOKUP_KEY), CONTACT_ID);
    final Uri entityUri = Uri.withAppendedPath(lookupUri, Contacts.Entity.CONTENT_DIRECTORY);

    ContactQueries queries = new ContactQueries();
    mContactsProvider.expectTypeQuery(rawContactUri, RawContacts.CONTENT_ITEM_TYPE);
    queries.fetchContactIdAndLookupFromRawContactUri(rawContactUri, CONTACT_ID, LOOKUP_KEY);
    queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);

    Contact contact = assertLoadContact(rawContactUri);

    assertEquals(CONTACT_ID, contact.getId());
    assertEquals(RAW_CONTACT_ID, contact.getNameRawContactId());
    assertEquals(DisplayNameSources.STRUCTURED_NAME, contact.getDisplayNameSource());
    assertEquals(LOOKUP_KEY, contact.getLookupKey());
    assertEquals(lookupUri, contact.getLookupUri());
    assertEquals(1, contact.getRawContacts().size());
    assertEquals(1, contact.getStatuses().size());
    mContactsProvider.verify();/*w w  w .  j a va2 s . c om*/
}

From source file:com.tct.mail.compose.ComposeActivity.java

@SuppressLint("NewApi")
public String getFilePath(Uri uri) {
    Uri thisUri = null;//from  w  ww  .  jav  a  2s.  c  om
    String path = "";

    ContentResolver cr = this.getContentResolver();
    if (uri == null) {
        return path;
    }
    thisUri = uri;

    try {

        String scheme = thisUri.getScheme();

        if (scheme == null) {
            path = thisUri.toString();
        } else if (scheme.equals("file")) {
            path = thisUri.getPath();
            path = changeDrmFileSuffix(path);
        }

        else if (DocumentsContract.isDocumentUri(this, uri)) {
            //ExternalStorageProvider
            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];
                }
            }
            // DownloadsProvider
            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(this, contentUri, null, null);
            }
            // MediaProvider
            else if (isMediaDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];
                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }
                contentUri = contentUri.withAppendedPath(contentUri, split[1]);
                return getDataColumn(this, contentUri, null, null);
            }
        }

        else if (scheme.equals("content")) {
            String[] projection = { "_data" };
            Cursor c = cr.query(thisUri, projection, null, null, null);
            if (c != null) {
                try {
                    if (c.moveToFirst()) {
                        path = c.getString(0);
                    }
                } finally {
                    c.close();
                }
            }

            if (path.endsWith("RAW")) {
                List<String> segments = thisUri.getPathSegments();
                String dbName = segments.get(0);
                String id = segments.get(1);
                path = this.getDatabasePath(dbName + "_att") + "/" + id;
            }

        }
    } catch (Exception e) {
    }
    return path;
}

From source file:cz.maresmar.sfm.view.menu.MenuDetailsFragment.java

@NonNull
@Override//from  w  w w .  j  a va 2s.  co  m
public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
    switch (id) {
    case MENU_LOADER_ID: {
        Uri menuUri = Uri.withAppendedPath(mUserUri, ProviderContract.MENU_ENTRY_PATH);
        return new CursorLoader(getContext(), menuUri, new String[] { ProviderContract.MenuEntry.STATUS,
                ProviderContract.MenuEntry.PORTAL_FEATURES, ProviderContract.MenuEntry.DATE,
                ProviderContract.MenuEntry.PRICE, ProviderContract.MenuEntry.TEXT,
                ProviderContract.MenuEntry.PORTAL_NAME, ProviderContract.MenuEntry.SYNCED_RESERVED_AMOUNT,
                ProviderContract.MenuEntry.SYNCED_OFFERED_AMOUNT,
                ProviderContract.MenuEntry.LOCAL_RESERVED_AMOUNT,
                ProviderContract.MenuEntry.LOCAL_OFFERED_AMOUNT,
                ProviderContract.MenuEntry.EDIT_RESERVED_AMOUNT, ProviderContract.MenuEntry.EDIT_OFFERED_AMOUNT,
                ProviderContract.MenuEntry.SYNCED_TAKEN_AMOUNT, ProviderContract.MenuEntry.REMAINING_TO_TAKE,
                ProviderContract.MenuEntry.REMAINING_TO_ORDER, ProviderContract.MenuEntry.LAST_ACTION_CHANGE,
                ProviderContract.MenuEntry.LABEL },
                ProviderContract.MenuEntry.ME_RELATIVE_ID + " = " + mMenuRelativeId + " AND "
                        + ProviderContract.MenuEntry.PORTAL_ID + " = " + mPortalId,
                null, null);
    }
    default:
        throw new UnsupportedOperationException("Unknown loader id: " + id);
    }
}

From source file:com.noshufou.android.su.service.ResultService.java

private void addLog(long appId, int callerUid, int execUid, String execCmd, int allow, long currentTime,
        String appLog, int all) {
    // Check to see if we should log
    if ((appLog == null && !mLog) || (appLog != null && appLog.equals("0")) || allow == -1) {
        return;//w  w  w  .  ja  v  a  2s . c  o m
    }

    ContentValues values = new ContentValues();
    if (appId == -1) {
        // App was not found in the database, add a row for logging purposes
        values.put(Apps.UID, callerUid);
        values.put(Apps.PACKAGE, Util.getAppPackage(this, callerUid));
        values.put(Apps.NAME, Util.getAppName(this, callerUid, false));
        values.put(Apps.EXEC_UID, execUid);
        values.put(Apps.EXEC_CMD, execCmd);
        values.put(Apps.ALLOW, all == 0 ? Apps.AllowType.ASK : allow);
        appId = Long.parseLong(getContentResolver().insert(Apps.CONTENT_URI, values).getLastPathSegment());
    }

    values.clear();
    values.put(Logs.DATE, currentTime);
    values.put(Logs.TYPE, allow);
    getContentResolver().insert(Uri.withAppendedPath(Logs.CONTENT_URI, String.valueOf(appId)), values);
}

From source file:com.ferid.app.frequentcontacts.selectnumber.SelectNumberActivity.java

/**
 * Retrieve photo of the given contact with contact ID
 * @param contactId// w w w .  j a  va2s  .c  o m
 * @return
 */
private String retrievePhoto(int contactId) {
    Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
    Uri photoUri = Uri.withAppendedPath(contactUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);

    Cursor cursor = getContentResolver().query(photoUri, new String[] { ContactsContract.Contacts.Photo.PHOTO },
            null, null, null);

    if (cursor == null) {
        return "";
    }

    try {
        if (cursor.moveToFirst()) {
            byte[] data = cursor.getBlob(0);
            if (data != null) {
                //byte[] to String convertion
                return Base64.encodeToString(data, Base64.DEFAULT);
            }
        }
    } finally {
        cursor.close();
    }

    return "";
}

From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java

/**
 * Insert new reading into Data table.//from ww w .  j av  a  2  s  .  c o m
 * 
 * @param metric       id of metric
 * @param monitor      id of monitor
 * @param timestamp    timestamp measured from uptime (milliseconds)
 * @param value        value of reading
 * @return    rowid of inserted row, -1 on failure
 * 
 * @see DataTable
 */
public synchronized long insertData(int metric, int monitor, long timestamp, float value) {
    if (DebugLog.DEBUG)
        Log.d(TAG, "CimonDatabaseAdapter.insertData - insert into Data table: metric-" + metric);
    ContentValues values = new ContentValues();
    values.put(DataTable.COLUMN_METRIC_ID, metric);
    values.put(DataTable.COLUMN_MONITOR_ID, monitor);
    values.put(DataTable.COLUMN_TIMESTAMP, timestamp);
    values.put(DataTable.COLUMN_VALUE, value);

    long rowid = database.insert(DataTable.TABLE_DATA, null, values);
    if (rowid >= 0) {
        Uri uri = Uri.withAppendedPath(CimonContentProvider.DATA_URI, String.valueOf(rowid));
        context.getContentResolver().notifyChange(uri, null);
    }

    return rowid;
}