MIME TYPE描述

多用途互联网邮件扩展(MIME,Multipurpose Internet Mail Extensions)是一个互联网标准,它扩展了电子邮件标准,使其能够支持非ASCII字符、二进制格式附件等多种格式的邮件消息。

内容类型(Content-Type),这个头部领域用于指定消息的类型。一般以下面的形式出现。[type]/[subtype]

type有下面的形式。

  • Text:用于标准化地表示的文本信息,文本消息可以是多种字符集和或者多种格式的;
  • Multipart:用于连接消息体的多个部分构成一个消息,这些部分可以是不同类型的数据;
  • Application:用于传输应用程序数据或者二进制数据;
  • Message:用于包装一个E-mail消息;
  • Image:用于传输静态图片数据;
  • Audio:用于传输音频或者音声数据;
  • Video:用于传输动态影像数据,可以是与音频编辑在一起的视频数据格式。

subtype用于指定type的详细形式。content-type/subtype配对的集合和与此相关的参数,将随着时间而增长。为了确保这些值在一个有序而且公开的状态下开发,MIME使用Internet Assigned Numbers Authority (IANA)作为中心的注册机制来管理这些值。常用的subtype值如下所示:

  • text/plain(纯文本
  • text/html(HTML文档)
  • application/xhtml+xml(XHTML文档)
  • image/gif(GIF图像)
  • image/jpeg(JPEG图像)【PHP中为:image/pjpeg】
  • image/png(PNG图像)【PHP中为:image/x-png】
  • video/mpeg(MPEG动画)
  • application/octet-stream(任意的二进制数据)
  • application/pdf(PDF文档)
  • application/msword(Microsoft Word文件)
  • message/rfc822(RFC 822形式)
  • multipart/alternative(HTML邮件的HTML形式和纯文本形式,相同内容使用不同形式表示)
  • application/x-www-form-urlencoded(使用HTTP的POST方法提交的表单)
  • multipart/form-data(同上,但主要用于表单提交时伴随文件上传的场合)

---------------------------------------------------------------------------------------------------------------------------

Android中MimeType的用途
                Intent-Filter中的<data>有一个mimeType . 它的作用是告诉Android系统本Activity可以处理的文件的类型。如设置为 “text/plain”表示可以处理“.txt”文件。
MimeTypeMap类
                MimeTypeMap类是专门处理mimeType的类。

---------------------------------------------------------------------------------------------------------------------------
类说明以及方法如下:

  1. Class Overview
  2. Two-way map that maps MIME-types to file extensions and vice versa.
  3. Summary
  4. Public Methods
  5. String
  6. getExtensionFromMimeType(String mimeType)
  7. Return the registered extension for the given MIME type.
  8. static String
  9. getFileExtensionFromUrl(String url)
  10. Returns the file extension or an empty string iff there is no extension.
  11. String
  12. getMimeTypeFromExtension(String extension)
  13. Return the MIME type for the given extension.
  14. staticMimeTypeMap
  15. getSingleton()
  16. Get the singleton instance of MimeTypeMap.
  17. boolean
  18. hasExtension(String extension)
  19. Return true if the given extension has a registered MIME type.
  20. boolean
  21. hasMimeType(String mimeType)
  22. Return true if the given MIME type has an entry in the map.

MimeTypeMap类是单例模式的,既没有公有的构造方法。使用getSinglton()方法获得MimeTypeMap对象:
       MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();

示例:

  1. public class MainActivity extends Activity {
  2. private String tag = "MainActivity";
  3. @Override
  4. public void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6. setContentView(R.layout.main);
  7. System.out.println(111);
  8. MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
  9. //MimeTypeMap中是否有txt的MimeType
  10. System.out.println(mimeTypeMap.hasExtension("txt"));
  11. System.out.println(mimeTypeMap.hasMimeType("text/html"));
  12. //获得txt文件类型的MimeType
  13. String extension = mimeTypeMap.getMimeTypeFromExtension("txt");
  14. System.out.println(extension);
  15. }
  16. }
---------------------------------------------------------------------------------------------------------------------------
在Android-4.2中,用MimeUtils类来管理所有支持的MimeType类型
  1. static {
  2. // The following table is based on /etc/mime.types data minus
  3. // chemical/* MIME types and MIME types that don't map to any
  4. // file extensions. We also exclude top-level domain names to
  5. // deal with cases like:
  6. //
  7. // mail.google.com/a/google.com
  8. //
  9. // and "active" MIME types (due to potential security issues).
  10. add("application/andrew-inset", "ez");
  11. add("application/dsptype", "tsp");
  12. add("application/futuresplash", "spl");
  13. add("application/hta", "hta");
  14. <span style="white-space:pre">  </span>...
---------------------------------------------------------------------------------------------------------------------------

如何使用:

实例代码为SDK自带的sample NotePad

startActivity(new Intent(Intent.ACTION_EDIT, uri));

其中uri为:content://com.google.provider.NotePad/notes/1

要启动的activity为

  1. <activity android:name="NoteEditor"
  2. android:theme="@android:style/Theme.Light"
  3. android:label="@string/title_note"
  4. android:screenOrientation="sensor"
  5. android:configChanges="keyboardHidden|orientation"
  6. >
  7. <!-- This filter says that we can view or edit the data of
  8. a single note -->
  9. <intent-filter android:label="@string/resolve_edit">
  10. <action android:name="android.intent.action.VIEW" />
  11. <action android:name="android.intent.action.EDIT" />
  12. <action android:name="com.android.notepad.action.EDIT_NOTE" />
  13. <category android:name="android.intent.category.DEFAULT" />
  14. <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
  15. </intent-filter>
  16. <!-- This filter says that we can create a new note inside
  17. of a directory of notes. -->
  18. <intent-filter>
  19. <action android:name="android.intent.action.INSERT" />
  20. <category android:name="android.intent.category.DEFAULT" />
  21. <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
  22. </intent-filter>
  23. </activity>

隐形Intent如何找到其对定的Activity?

1.系统从intent中获取道uri,得到了content://com.google.provider.NotePad/notes/1,

去掉开始的content:标识,得到com.google.provider.NotePad/notes/1,

然后获取前面的com.google.provider.NotePad,然后就到Androidmanfest.xml中

找到authorities为com.google.provider.NotePad的provider,

然后就加载这个content provider

  1. <provider android:name="NotePadProvider"
  2. android:authorities="com.google.provider.NotePad"
  3. />

2.然后调用NotePadProvider的gettype函数,并把上述URI传给这个函数,

函数返回URI所对应的类型,这里返回Notes.CONTENT_ITEM_TYPE,代表一条日志记录,

而CONTENT_ITEM_TYPE = " vnd.android.cursor.item/vnd.google.note "

  1. @Override
  2. public String getType(Uri uri) {
  3. switch (sUriMatcher.match(uri)) {
  4. case NOTES:
  5. return Notes.CONTENT_TYPE;
  6. case NOTE_ID:
  7. return Notes.CONTENT_ITEM_TYPE;
  8. default:
  9. throw new IllegalArgumentException("Unknown URI " + uri);
  10. }
  11. }

3.然后系统使用获得的" vnd.android.cursor.item/vnd.google.note "和

”android.intent.action.EDIT”到androidmanfest.xml中去找匹配的activity.

其中:android:authorities="com.google.provider.NotePad" 这段代码是指定此ContentProvider的authorities,

类似于activity中的IntentFilter中action的作用,说白了就是这个ContentProvider在一个

android系统中的名字。ContentProvider在这个应用程序启动以后,

就会永远存在android系统中,直到卸载这个应用程序。

参考网页:http://www.cnblogs.com/newcj/archive/2011/08/10/2134305.html

参考网页:http://blog.csdn.net/janronehoo/article/details/7514883

参考网页:http://blog.csdn.net/txj8612/article/details/8783998

Android MimeType的用途以及所有类型的更多相关文章

  1. Android MimeType的用法和几种类型

    关于MIME TYPE描述 多用途互联网邮件扩展(MIME,Multipurpose Internet Mail Extensions)是一个互联网标准,它扩展了电子邮件标准,使其能够支持非ASCII ...

  2. Android:mimeType

    接收从其他应用传过来的数据,要用到清单文件 <activity android:name="com.terry.myActivity2" android:label=&quo ...

  3. 【整理】Android中EditText中的InputType类型含义与如何定义( 转 )

    转自:[整理]Android中EditText中的InputType类型含义与如何定义 用到的时候查到了这篇文章觉得很不错,就在此记录下. [背景] 经过一些Android中EditText方面的折腾 ...

  4. android Bundle savedInstanceState用途

    经常会出现用户按到home键,退出了界面,或者安卓系统意外回收了应用的进程,这种情况下,使用Bundle savedInstanceState就可以用户再次打开应用的时候恢复的原来的状态 (以下转自: ...

  5. android十六进制颜色代码转换为int类型数值

    android开发中将十六进制颜色代码转换为int类型数值方法:Color.parseColor("#00CCFF")返回int数值;

  6. 【转】Android中EditText中的InputType类型含义与如何定义

    原文网址:http://www.crifan.com/summary_android_edittext_inputtype_values_and_meaning_definition/ 经过一些And ...

  7. Android attrs.xml文件中属性类型format值的格式

    "reference" //引用 "color" //颜色 "boolean" //布尔值 "dimension" // ...

  8. xamarin android如何将Java.Lang.Object类型转成C#类型

    问题起源 其实这个标题也可以换一个更准确一点,因为我遇到的问题是: xamarin android中的Class继承了Java.Lang.Object ,将json序列化成c#类型时发现无法赋值,序列 ...

  9. Android开发 Context详解与类型 转载

    转载地址:https://blog.csdn.net/guolin_blog/article/details/47028975 个人总结: Context分为 activity : activity其 ...

随机推荐

  1. 【树形dp】hdu6035 Colorful Tree

    非常棒的题解,我就不复述了:http://blog.csdn.net/Bahuia/article/details/76141574 O(n) #include<cstdio> #incl ...

  2. LeetCode 771. 宝石与石头(java)

    给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符都是字母 ...

  3. JavaScript的深拷贝与浅拷贝

    深拷贝和浅拷贝是在面试中经常遇到的问题.今天在这里总结一下. 深拷贝与浅拷贝的问题,涉及到JavaScript的变量类型,先来说说变量的类型,变量类型包括基本类型和引用类型. 基本类型:Undefin ...

  4. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  5. Codeforces Round #343 (Div. 2) E. Famil Door and Roads lca 树形dp

    E. Famil Door and Roads 题目连接: http://www.codeforces.com/contest/629/problem/E Description Famil Door ...

  6. 【个人专用&入门级】LAMP一键安装包

    最近自学了下Shell编程,也算是入门吧!按照如下教程,编译安装了LAMP(Apache-2.4.6 + MySQL-5.5.25 + PHP-5.3.27) CentOS6.3编译安装LAMP(1) ...

  7. class"org.apache.commons.dbcp.BasicDataSource"not found出错的解决办法

    法1:在项目上右击build path->configure build path..->add library..->MyEclipse Libraries选中Spring 2.0 ...

  8. 报错:configure: error: no acceptable C compiler found in $PATH

    运行以下命令报错: ./configure 错误: checking whether to enable maintainer-specific portions of Makefiles... ye ...

  9. 【笔记】js原生方法 在元素外部或内部实现添加元素功能(类似jq 的 insert 和 append)

    介绍的这个方法是:insetAdjacentHTML() 方法 此方法接收两个参数: 第一个参数必为下列值: beforebegin:在调用的元素外部的前面添加一个目标元素 afterend:在调用元 ...

  10. 不输入sudo使用docker

    系统是debian系 安装: sudo apt install docker.io 将当前用户加入‘docker’组: sudo gpasswd -a ${USER} docker  刷新权限: su ...