android.net.Uri.withAppendedPath()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(282)

本文整理了Java中android.net.Uri.withAppendedPath()方法的一些代码示例,展示了Uri.withAppendedPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Uri.withAppendedPath()方法的具体详情如下:
包路径:android.net.Uri
类名称:Uri
方法名:withAppendedPath

Uri.withAppendedPath介绍

[英]Creates a new Uri by appending an already-encoded path segment to a base Uri.
[中]通过将已编码的路径段附加到基本Uri来创建新的Uri。

代码示例

代码示例来源:origin: google/ExoPlayer

/** Returns a fixed SmoothStreaming client manifest {@link Uri}. */
public static Uri fixManifestUri(Uri manifestUri) {
 if (Util.toLowerInvariant(manifestUri.getLastPathSegment()).matches("manifest(\\(.+\\))?")) {
  return manifestUri;
 }
 return Uri.withAppendedPath(manifestUri, "Manifest");
}

代码示例来源:origin: robolectric/robolectric

@Implementation
protected static Uri withAppendedId(Uri contentUri, long id) {
 return Uri.withAppendedPath(contentUri, String.valueOf(id));
}

代码示例来源:origin: k9mail/k-9

public void notifyChange() {
  Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + account.getUuid() + "/messages");
  contentResolver.notifyChange(uri, null);
}

代码示例来源:origin: grandcentrix/tray

@NonNull
private static Uri generateContentUri(@NonNull final Context context, final String basepath) {
  final String authority = getAuthority(context);
  final Uri authorityUri = Uri.parse("content://" + authority);
  //noinspection UnnecessaryLocalVariable
  final Uri contentUri = Uri.withAppendedPath(authorityUri, basepath);
  return contentUri;
}

代码示例来源:origin: bumptech/glide

private List<MediaStoreData> query(Uri contentUri, String[] projection, String sortByCol,
  String idCol, String dateTakenCol, String dateModifiedCol, String mimeTypeCol,
  String orientationCol, MediaStoreData.Type type) {
 final List<MediaStoreData> data = new ArrayList<MediaStoreData>();
 Cursor cursor = getContext().getContentResolver()
   .query(contentUri, projection, null, null, sortByCol + " DESC");
 if (cursor == null) {
  return data;
 }
 try {
  final int idColNum = cursor.getColumnIndexOrThrow(idCol);
  final int dateTakenColNum = cursor.getColumnIndexOrThrow(dateTakenCol);
  final int dateModifiedColNum = cursor.getColumnIndexOrThrow(dateModifiedCol);
  final int mimeTypeColNum = cursor.getColumnIndex(mimeTypeCol);
  final int orientationColNum = cursor.getColumnIndexOrThrow(orientationCol);
  while (cursor.moveToNext()) {
   long id = cursor.getLong(idColNum);
   long dateTaken = cursor.getLong(dateTakenColNum);
   String mimeType = cursor.getString(mimeTypeColNum);
   long dateModified = cursor.getLong(dateModifiedColNum);
   int orientation = cursor.getInt(orientationColNum);
   data.add(new MediaStoreData(id, Uri.withAppendedPath(contentUri, Long.toString(id)),
     mimeType, dateTaken, dateModified, orientation, type));
  }
 } finally {
  cursor.close();
 }
 return data;
}

代码示例来源:origin: ankidroid/Anki-Android

/**
 * Get the ID for the note type / model which is currently in use
 * @return id for current model, or &lt;0 if there was a problem
 */
public long getCurrentModelId() {
  // Get the current model
  Uri uri = Uri.withAppendedPath(Model.CONTENT_URI, Model.CURRENT_MODEL_ID);
  final Cursor singleModelCursor = mResolver.query(uri, null, null, null, null);
  if (singleModelCursor == null) {
    return -1L;
  }
  long modelId;
  try {
    singleModelCursor.moveToFirst();
    modelId = singleModelCursor.getLong(singleModelCursor.getColumnIndex(Model._ID));
  } finally {
    singleModelCursor.close();
  }
  return modelId;
}

代码示例来源:origin: rey5137/material

public RecipientSpan(Recipient recipient) {
  super(TextUtils.isEmpty(recipient.name) ? recipient.number : recipient.name,
      mSpanHeight, mSpanMaxWidth, mSpanPaddingLeft, mSpanPaddingRight, mSpanTypeface, mSpanTextColor, mSpanTextSize, mSpanBackgroundColor);
  mRecipient = recipient;
  if(TextUtils.isEmpty(recipient.lookupKey))
    setImageResource(mDefaultAvatarId);
  else
    Picasso.with(getContext())
        .load(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, recipient.lookupKey))
        .placeholder(mDefaultAvatarId)
        .into(this);
}

代码示例来源:origin: bumptech/glide

@Override
 public void onClick(View v) {
  Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                  Uri.encode(numberEntry.getText().toString()));
  GlideApp.with(MainActivity.this)
      .load(uri)
      .override(Target.SIZE_ORIGINAL)
      .into(imageViewLookup);
  }
});

代码示例来源:origin: grandcentrix/tray

private static Uri getContentUri(final String basepath) {
    final Uri authorityUri = Uri.parse("content://" + AUTHORITY);
    return Uri.withAppendedPath(authorityUri, basepath);
  }
}

代码示例来源:origin: k9mail/k-9

/**
   * Notify all concerned parties that the message list has changed.
   *
   * <p><strong>Note:</strong>
   * Notifying the content resolver of the change will cause the {@code CursorLoader} in
   * {@code MessageListFragment} to reload the cursor. But especially with flag changes this will
   * block because of the DB write operation to update the flags. So additionally we use
   * {@link LocalBroadcastManager} to send a {@link #ACTION_CACHE_UPDATED} broadcast. This way
   * {@code MessageListFragment} can update the view without reloading the cursor.
   * </p>
   */
  private void notifyChange() {
    LocalBroadcastManager.getInstance(sContext).sendBroadcast(new Intent(ACTION_CACHE_UPDATED));

    Uri uri = Uri.withAppendedPath(EmailProvider.CONTENT_URI, "account/" + mAccountUuid +
        "/messages");
    sContext.getContentResolver().notifyChange(uri, null);
  }
}

代码示例来源:origin: bumptech/glide

@Before
public void setUp() {
 MockitoAnnotations.initMocks(this);
 uri = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, "123");
 fetcher = new ThumbFetcher(uri, opener);
}

代码示例来源:origin: k9mail/k-9

@Override
public void onClick(View v) {
  // If contact has been assigned, extras should no longer be null, but do a null check
  // anyway just in case assignContactFromPhone or Email was called with a null bundle or
  // wasn't assigned previously.
  final Bundle extras = (this.extras == null) ? new Bundle() : this.extras;
  if (contactUri != null) {
    QuickContact.showQuickContact(getContext(), ContactBadge.this, contactUri,
        QuickContact.MODE_LARGE, null);
  } else if (contactEmail != null) {
    extras.putString(EXTRA_URI_CONTENT, contactEmail);
    queryHandler.startQuery(TOKEN_EMAIL_LOOKUP_AND_TRIGGER, extras,
        Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(contactEmail)),
        EMAIL_LOOKUP_PROJECTION, null, null, null);
  }
}

代码示例来源:origin: k9mail/k-9

/**
 * Return a {@link Cursor} instance that can be used to fetch information
 * about the contact with the given email address.
 *
 * @param address The email address to search for.
 * @return A {@link Cursor} instance that can be used to fetch information
 *         about the contact with the given email address
 */
private Cursor getContactByAddress(final String address) {
  final Uri uri = Uri.withAppendedPath(ContactsContract.CommonDataKinds.Email.CONTENT_LOOKUP_URI, Uri.encode(address));
  if (hasContactPermission()) {
    return mContentResolver.query(
        uri,
        PROJECTION,
        null,
        null,
        SORT_ORDER);
  } else {
    return new EmptyCursor();
  }
}

代码示例来源:origin: rey5137/material

@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ContactView v = (ContactView)convertView;
    if(v == null) {
      v = (ContactView)LayoutInflater.from(parent.getContext()).inflate(position == 0 ? R.layout.row_contact_selected : R.layout.row_contact_replace, parent, false);
      v.setOnClickListener(this);
    }
    v.setTag(position);
    Recipient recipient = (Recipient)getItem(position);
    v.setNameText(position == 0 ? recipient.name : null);
    v.setAddressText(recipient.number);
    if(TextUtils.isEmpty(recipient.lookupKey))
      v.setAvatarResource(mDefaultAvatarId);
    else
      Picasso.with(getContext())
          .load(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, recipient.lookupKey))
          .placeholder(mDefaultAvatarId)
          .into(v);
    return v;
  }
}

代码示例来源:origin: rey5137/material

@Override
public View getView(int position, View convertView, ViewGroup parent) {
  ContactView v = (ContactView)convertView;
  if (v == null)
    v = new ContactView(getContext(), null, 0, R.style.ContactView);
  Recipient recipient = (Recipient) getItem(position);
  v.setNameText(recipient.name);
  v.setAddressText(recipient.number);
  if(TextUtils.isEmpty(recipient.lookupKey))
    v.setAvatarResource(mDefaultAvatarId);
  else
    Picasso.with(getContext())
        .load(Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, recipient.lookupKey))
        .placeholder(mDefaultAvatarId)
        .into(v);
  return v;
}

代码示例来源:origin: k9mail/k-9

/**
 * Assign a contact based on an email address. This should only be used when
 * the contact's URI is not available, as an extra query will have to be
 * performed to lookup the URI based on the email.
 *
 * @param emailAddress
 *         The email address of the contact.
 * @param lazyLookup
 *         If this is true, the lookup query will not be performed
 *         until this view is clicked.
 * @param extras
 *         A bundle of extras to populate the contact edit page with if the contact
 *         is not found and the user chooses to add the email address to an existing contact or
 *         create a new contact. Uses the same string constants as those found in
 *         {@link android.provider.ContactsContract.Intents.Insert}
 */
public void assignContactFromEmail(String emailAddress, boolean lazyLookup, Bundle extras) {
  contactEmail = emailAddress;
  this.extras = extras;
  if (!lazyLookup) {
    queryHandler.startQuery(TOKEN_EMAIL_LOOKUP, null,
        Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(contactEmail)),
        EMAIL_LOOKUP_PROJECTION, null, null, null);
  } else {
    contactUri = null;
    onContactUriChanged();
  }
}

代码示例来源:origin: robolectric/robolectric

@Test(expected = NumberFormatException.class)
public void parseIdThrowsNumberFormatException() {
 ContentUris.parseId(Uri.withAppendedPath(URI, "bar"));
}

代码示例来源:origin: bumptech/glide

private void showContact(long id) {
  GlideRequests glideRequests = GlideApp.with(this);
  RequestOptions originalSize = new RequestOptions().override(Target.SIZE_ORIGINAL);

  Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, id);
  glideRequests.load(contactUri).apply(originalSize).into(imageViewContact);

  Uri lookupUri = Contacts.getLookupUri(getContentResolver(), contactUri);
  glideRequests.load(lookupUri).apply(originalSize).into(imageViewLookup);

  Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
  glideRequests.load(photoUri).apply(originalSize).into(imageViewPhoto);

  Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
  glideRequests.load(displayPhotoUri).apply(originalSize).into(imageViewDisplayPhoto);
 }
}

代码示例来源:origin: robolectric/robolectric

@Test public void canParseId() {
 assertThat(ContentUris.parseId(Uri.withAppendedPath(URI, "1"))).isEqualTo(1L);
 assertThat(ContentUris.parseId(URI)).isEqualTo(-1L);
}

代码示例来源:origin: grandcentrix/tray

public void testDelete() throws Exception {
  final Uri[] workingUris = {
      mTrayUri.get(),
      mTrayUri.builder().setModule("module").build(),
      mTrayUri.builder().setModule("module").setKey("key").build(),
      mTrayUri.getInternal(),
      mTrayUri.builder().setInternal(true).setModule("module").build(),
      mTrayUri.builder().setInternal(true).setModule("module").setKey("key").build()
  };
  for (Uri uri : workingUris) {
    getProviderMockContext().getContentResolver().delete(uri, null, null);
  }
  final Uri badUri = Uri
      .withAppendedPath(Uri.parse("content://" + MockProvider.AUTHORITY), "something");
  try {
    getProviderMockContext().getContentResolver().delete(badUri, null, null);
    fail();
  } catch (IllegalArgumentException e) {
    assertTrue(e.getMessage().contains("not supported"));
  }
}

相关文章