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:com.geniusgithub.contact.contact.calllog.ContactInfoHelper.java

/**
 * Determines the contact information for the given phone number.
 * <p>//from w  w w  .  j  a v a2  s .co  m
 * It returns the contact info if found.
 * <p>
 * If no contact corresponds to the given phone number, returns {@link ContactInfo#EMPTY}.
 * <p>
 * If the lookup fails for some other reason, it returns null.
 */
private ContactInfo queryContactInfoForPhoneNumber(String number, String countryIso) {
    String contactNumber = number;
    if (!TextUtils.isEmpty(countryIso)) {
        // Normalize the number: this is needed because the PhoneLookup query below does not
        // accept a country code as an input.
        String numberE164 = PhoneNumberUtils.formatNumberToE164(number, countryIso);
        if (!TextUtils.isEmpty(numberE164)) {
            // Only use it if the number could be formatted to E164.
            contactNumber = numberE164;
        }
    }

    // The "contactNumber" is a regular phone number, so use the PhoneLookup table.
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(contactNumber));
    ContactInfo info = lookupContactFromUri(uri);
    if (info != null && info != ContactInfo.EMPTY) {
        info.formattedNumber = formatPhoneNumber(number, null, countryIso);
    } else if (mCachedNumberLookupService != null) {
        CachedContactInfo cacheInfo = mCachedNumberLookupService.lookupCachedContactFromNumber(mContext,
                number);
        if (cacheInfo != null) {
            info = cacheInfo.getContactInfo().isBadData ? null : cacheInfo.getContactInfo();
        } else {
            info = null;
        }
    }
    return info;
}

From source file:com.noshufou.android.su.AppDetailsFragment.java

private void doToggle() {
    ContentResolver cr = getActivity().getContentResolver();
    Uri uri = Uri.withAppendedPath(Apps.CONTENT_URI, String.valueOf(mShownIndex));

    ContentValues values = new ContentValues();
    values.put(Apps.ALLOW, mAllow == 1 ? 0 : 1);
    cr.update(uri, values, null, null);/*from ww  w.j  av  a  2  s  .co  m*/

    // Update the log
    values.clear();
    values.put(Logs.DATE, System.currentTimeMillis());
    values.put(Logs.TYPE, Logs.LogType.TOGGLE);
    cr.insert(Uri.withAppendedPath(Logs.CONTENT_URI, String.valueOf(mShownIndex)), values);
    Intent intent = new Intent(getActivity(), ResultService.class);
    intent.putExtra(ResultService.EXTRA_ACTION, ResultService.ACTION_RECYCLE);
    getActivity().startService(intent);
}

From source file:org.smssecure.smssecure.contacts.ContactAccessor.java

public List<String> getNumbersForThreadSearchFilter(Context context, String constraint) {
    LinkedList<String> numberList = new LinkedList<>();
    Cursor cursor = null;/*  w ww  . j  ava 2  s  . c  o  m*/

    try {
        cursor = context.getContentResolver().query(
                Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(constraint)), null, null, null, null);

        while (cursor != null && cursor.moveToNext()) {
            numberList.add(cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER)));
        }

    } finally {
        if (cursor != null)
            cursor.close();
    }

    GroupDatabase.Reader reader = null;
    GroupRecord record;

    try {
        reader = DatabaseFactory.getGroupDatabase(context).getGroupsFilteredByTitle(constraint);

        while ((record = reader.getNext()) != null) {
            numberList.add(record.getEncodedId());
        }
    } finally {
        if (reader != null)
            reader.close();
    }

    return numberList;
}

From source file:com.securecomcode.text.contacts.ContactAccessor.java

public List<String> getNumbersForThreadSearchFilter(String constraint, ContentResolver contentResolver) {
    LinkedList<String> numberList = new LinkedList<String>();
    Cursor cursor = null;//from w  w  w . j  a v a 2  s  .c o m

    try {
        cursor = contentResolver.query(Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(constraint)),
                null, null, null, null);

        while (cursor != null && cursor.moveToNext()) {
            numberList.add(cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER)));
        }

    } finally {
        if (cursor != null)
            cursor.close();
    }

    return numberList;
}

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

public void testLoadContactWithContactLookupAndIdUri() {
    // Use lookup-style Uris that also contain the 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(lookupUri, Contacts.CONTENT_ITEM_TYPE);
    queries.fetchAllData(entityUri, CONTACT_ID, RAW_CONTACT_ID, DATA_ID, LOOKUP_KEY);

    Contact contact = assertLoadContact(lookupUri);

    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();//from w  w w . j  av a2s  .  c  om
}

From source file:com.bitants.wally.fragments.SavedImagesFragment.java

private ArrayList<Uri> getFileUrisFromCursor(Cursor cursor) {
    ArrayList<Uri> filePaths = new ArrayList<Uri>();
    if (cursor != null) {
        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
        while (cursor.moveToNext()) {
            int imageID = cursor.getInt(columnIndex);
            Uri uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                    Integer.toString(imageID));
            filePaths.add(uri);/*from  w ww. j a v a2s  . c  o  m*/
        }
    }
    return filePaths;
}

From source file:com.appjma.appdeployer.AppFragment.java

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    switch (id) {
    case LOADER_APP_VERSIONS: {
        Uri uri = Uri.withAppendedPath(mUri, AppContract.AppVersions.CONTENT_PATH);
        return new CursorLoader(getActivity(), uri, AppVersionsAdapter.PROJECTION, null, null,
                AppContract.AppVersions.UPDATED_AT);
    }//from w  w  w  . j a  v  a  2s . c  om
    case LOADER_APP: {
        Uri uri = mUri.buildUpon().appendQueryParameter("limit", "1").build();
        return new CursorLoader(getActivity(), uri, PROJECTION, null, null, AppContract.Apps.UPDATED_AT);
    }
    default:
        throw new RuntimeException("Unknown laoder id: " + id);
    }
}

From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java

/**
 * ???/* w  w  w .j a va 2s.com*/
 *
 * @param messageType
 *            ?MMS,SMS,Email
 * @param folderType
 *            
 * @return ??
 */
@SuppressLint("DefaultLocale")
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:org.mariotaku.twidere.provider.TwidereDataProvider.java

@Override
public Uri insert(final Uri uri, final ContentValues values) {
    try {/*  ww  w  .ja  v  a 2  s. c  o  m*/
        final int table_id = getTableId(uri);
        final String table = getTableNameById(table_id);
        checkWritePermission(table_id, table);
        switch (table_id) {
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATION:
        case TABLE_ID_DIRECT_MESSAGES:
        case TABLE_ID_DIRECT_MESSAGES_CONVERSATIONS_ENTRY:
            return null;
        }
        if (table == null)
            return null;
        final long row_id = mDatabase.insert(table, null, values);
        if (!"false".equals(uri.getQueryParameter(QUERY_PARAM_NOTIFY))) {
            switch (getTableId(uri)) {
            case TABLE_ID_STATUSES: {
                mNewStatusesCount++;
                break;
            }
            default:
            }
        }
        onDatabaseUpdated(uri);
        onNewItemsInserted(uri, values);
        return Uri.withAppendedPath(uri, String.valueOf(row_id));
    } catch (final SQLException e) {
        throw new IllegalStateException(e);
    }
}

From source file:at.flack.receiver.SmsReceiver.java

public static String getContactName(Context context, String phoneNumber) {
    ContentResolver cr = context.getContentResolver();
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
    Cursor cursor = cr.query(uri, new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
    if (cursor == null) {
        return null;
    }/*from   w  ww .  ja v a2 s.  c o m*/
    String contactName = null;
    if (cursor.moveToFirst()) {
        contactName = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME));
    }

    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }

    return contactName;
}