ContentProvider官方教程(8)自定义MIME

MIME Type Reference

  Content providers can return standard MIME media types, or custom MIME type strings, or both.

  provider支持标准MIME和自定义的MIME

  MIME types have the format 标准MIME格式如下:

  type/subtype

  For example, the well-known MIME type text/html has the text type and the html subtype. If the provider returns this type for a URI, it means that a query using that URI will return text containing HTML tags.

  Custom MIME type strings, also called "vendor-specific" MIME types, have more complex type and subtype values. The type value is always

 自定义的MIME基类型总是下面两个:而子类型是自定义的。
  • vnd.android.cursor.dir for multiple rows,
  • vnd.android.cursor.item for a single row.

  The subtype is provider-specific. The Android built-in providers usually have a simple subtype. For example, when the Contacts application creates a row for a telephone number, it sets the following MIME type in the row:

  举例:
  vnd.android.cursor.item/phone_v2

  Notice that the subtype value is simply phone_v2.

  Other provider developers may create their own pattern of subtypes based on the provider's authority and table names. For example, consider a provider that contains train timetables. The provider's authority is com.example.trains, and it contains the tables Line1, Line2, and Line3.

In response to the content URI  for table Line1:

content://com.example.trains/Line1

the provider returns the MIME type

vnd.android.cursor.dir/vnd.example.line1

In response to the content URI  for row 5 in table Line2:

content://com.example.trains/Line2/5

the provider returns the MIME type

vnd.android.cursor.item/vnd.example.line2

  

  Most content providers define contract class constants for the MIME types they use. The Contacts Provider contract class ContactsContract.RawContacts, for example, defines the constant CONTENT_ITEM_TYPE for the MIME type of a single raw contact row.

  Content URIs for single rows are described in the section Content URIs.

上一篇:【Nginx】使用certbot安装免费https证书使Nginx支持Https请求


下一篇:js中一些容易混淆的方法