android.content.Intent.normalizeMimeType()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(2.3k)|赞(0)|评价(0)|浏览(220)

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

Intent.normalizeMimeType介绍

[英]Normalize a MIME data type.

A normalized MIME type has white-space trimmed, content-type parameters removed, and is lower-case. This aligns the type with Android best practices for intent filtering.

For example, "text/plain; charset=utf-8" becomes "text/plain". "text/x-vCard" becomes "text/x-vcard".

All MIME types received from outside Android (such as user input, or external sources like Bluetooth, NFC, or the Internet) should be normalized before they are used to create an Intent.
[中]规范化MIME数据类型。
规范化的MIME类型会修剪空白,删除内容类型参数,并且是小写。这使该类型与Android的意图过滤最佳实践保持一致。
例如,“text/plain;charset=utf-8”变为“text/plain”。“文本/x-vCard”变为“文本/x-vCard”。
从Android外部接收的所有MIME类型(如用户输入,或蓝牙、NFC或互联网等外部源)在用于创建意图之前都应该进行规范化。

代码示例

代码示例来源:origin: ac-pm/Inspeckage

i.normalizeMimeType(mimetype);

代码示例来源:origin: ac-pm/Inspeckage

i.normalizeMimeType(mimetype);

代码示例来源:origin: skjolber/ndef-tools-for-android

/**
 * Map this record to a MIME type, or return null if it cannot be mapped.<p>
 * Currently this method considers all {@link #TNF_MIME_MEDIA} records to
 * be MIME records, as well as some {@link #TNF_WELL_KNOWN} records such as
 * {@link #RTD_TEXT}. If this is a MIME record then the MIME type as string
 * is returned, otherwise null is returned.<p>
 * This method does not perform validation that the MIME type is
 * actually valid. It always attempts to
 * return a string containing the type if this is a MIME record.<p>
 * The returned MIME type will by normalized to lower-case using
 * {@link Intent#normalizeMimeType}.<p>
 * The MIME payload can be obtained using {@link #getPayload}.
 *
 * @return MIME type as a string, or null if this is not a MIME record
 */
public String toMimeType() {
  switch (mTnf) {
    case NdefRecord.TNF_WELL_KNOWN:
      if (Arrays.equals(mType, NdefRecord.RTD_TEXT)) {
        return "text/plain";
      }
      break;
    case NdefRecord.TNF_MIME_MEDIA:
      String mimeType = new String(mType, Charset.forName("US-ASCII"));
      return Intent.normalizeMimeType(mimeType);
  }
  return null;
}

代码示例来源:origin: skjolber/ndef-tools-for-android

mimeType = Intent.normalizeMimeType(mimeType);
if (mimeType.length() == 0) throw new IllegalArgumentException("mimeType is empty");
int slashIndex = mimeType.indexOf('/');

相关文章

Intent类方法