Android MimeType的用途以及所有类型
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的类。
---------------------------------------------------------------------------------------------------------------------------
类说明以及方法如下:
- Class Overview
- Two-way map that maps MIME-types to file extensions and vice versa.
- Summary
- Public Methods
- String
- getExtensionFromMimeType(String mimeType)
- Return the registered extension for the given MIME type.
- static String
- getFileExtensionFromUrl(String url)
- Returns the file extension or an empty string iff there is no extension.
- String
- getMimeTypeFromExtension(String extension)
- Return the MIME type for the given extension.
- staticMimeTypeMap
- getSingleton()
- Get the singleton instance of MimeTypeMap.
- boolean
- hasExtension(String extension)
- Return true if the given extension has a registered MIME type.
- boolean
- hasMimeType(String mimeType)
- Return true if the given MIME type has an entry in the map.
MimeTypeMap类是单例模式的,既没有公有的构造方法。使用getSinglton()方法获得MimeTypeMap对象:
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
示例:
- public class MainActivity extends Activity {
- private String tag = "MainActivity";
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- System.out.println(111);
- MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
- //MimeTypeMap中是否有txt的MimeType
- System.out.println(mimeTypeMap.hasExtension("txt"));
- System.out.println(mimeTypeMap.hasMimeType("text/html"));
- //获得txt文件类型的MimeType
- String extension = mimeTypeMap.getMimeTypeFromExtension("txt");
- System.out.println(extension);
- }
- }
- static {
- // The following table is based on /etc/mime.types data minus
- // chemical/* MIME types and MIME types that don't map to any
- // file extensions. We also exclude top-level domain names to
- // deal with cases like:
- //
- // mail.google.com/a/google.com
- //
- // and "active" MIME types (due to potential security issues).
- add("application/andrew-inset", "ez");
- add("application/dsptype", "tsp");
- add("application/futuresplash", "spl");
- add("application/hta", "hta");
- <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为
- <activity android:name="NoteEditor"
- android:theme="@android:style/Theme.Light"
- android:label="@string/title_note"
- android:screenOrientation="sensor"
- android:configChanges="keyboardHidden|orientation"
- >
- <!-- This filter says that we can view or edit the data of
- a single note -->
- <intent-filter android:label="@string/resolve_edit">
- <action android:name="android.intent.action.VIEW" />
- <action android:name="android.intent.action.EDIT" />
- <action android:name="com.android.notepad.action.EDIT_NOTE" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="vnd.android.cursor.item/vnd.google.note" />
- </intent-filter>
- <!-- This filter says that we can create a new note inside
- of a directory of notes. -->
- <intent-filter>
- <action android:name="android.intent.action.INSERT" />
- <category android:name="android.intent.category.DEFAULT" />
- <data android:mimeType="vnd.android.cursor.dir/vnd.google.note" />
- </intent-filter>
- </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
- <provider android:name="NotePadProvider"
- android:authorities="com.google.provider.NotePad"
- />
2.然后调用NotePadProvider的gettype函数,并把上述URI传给这个函数,
函数返回URI所对应的类型,这里返回Notes.CONTENT_ITEM_TYPE,代表一条日志记录,
而CONTENT_ITEM_TYPE = " vnd.android.cursor.item/vnd.google.note "
- @Override
- public String getType(Uri uri) {
- switch (sUriMatcher.match(uri)) {
- case NOTES:
- return Notes.CONTENT_TYPE;
- case NOTE_ID:
- return Notes.CONTENT_ITEM_TYPE;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
- }
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的用途以及所有类型的更多相关文章
- Android MimeType的用法和几种类型
关于MIME TYPE描述 多用途互联网邮件扩展(MIME,Multipurpose Internet Mail Extensions)是一个互联网标准,它扩展了电子邮件标准,使其能够支持非ASCII ...
- Android:mimeType
接收从其他应用传过来的数据,要用到清单文件 <activity android:name="com.terry.myActivity2" android:label=&quo ...
- 【整理】Android中EditText中的InputType类型含义与如何定义( 转 )
转自:[整理]Android中EditText中的InputType类型含义与如何定义 用到的时候查到了这篇文章觉得很不错,就在此记录下. [背景] 经过一些Android中EditText方面的折腾 ...
- android Bundle savedInstanceState用途
经常会出现用户按到home键,退出了界面,或者安卓系统意外回收了应用的进程,这种情况下,使用Bundle savedInstanceState就可以用户再次打开应用的时候恢复的原来的状态 (以下转自: ...
- android十六进制颜色代码转换为int类型数值
android开发中将十六进制颜色代码转换为int类型数值方法:Color.parseColor("#00CCFF")返回int数值;
- 【转】Android中EditText中的InputType类型含义与如何定义
原文网址:http://www.crifan.com/summary_android_edittext_inputtype_values_and_meaning_definition/ 经过一些And ...
- Android attrs.xml文件中属性类型format值的格式
"reference" //引用 "color" //颜色 "boolean" //布尔值 "dimension" // ...
- xamarin android如何将Java.Lang.Object类型转成C#类型
问题起源 其实这个标题也可以换一个更准确一点,因为我遇到的问题是: xamarin android中的Class继承了Java.Lang.Object ,将json序列化成c#类型时发现无法赋值,序列 ...
- Android开发 Context详解与类型 转载
转载地址:https://blog.csdn.net/guolin_blog/article/details/47028975 个人总结: Context分为 activity : activity其 ...
随机推荐
- [UOJ336]无限之环
题目的要求就是每个接头都有且仅有一个与其相连的接头,所以不妨给每个接头$1$的流量,对整个网格图黑白染色后(源点$\mathop\rightarrow\limits^\infty$黑点,白点$\mat ...
- [转]SpringMVC入门
目录 介绍 实例 总结 参考资料 介绍 SpringMVC是一款Web MVC框架. 它跟Struts框架类似,是目前主流的Web MVC框架之一. 本文通过实例来介绍SpringMVC的入门知识. ...
- Codeforces Gym 100269D Dwarf Tower spfa
Dwarf Tower 题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a ...
- 简单实现ToolStripMenuItem(菜单栏)的单选效果
来源:http://www.97world.com/archives/2194 这几天在写又拍云的客户端,老实说确实学到了不少东西!接下来的几天我会把一些技巧或者原来没有接触过的一些东西发上来,算是复 ...
- 认识udev
转:http://www.360doc.com/content/11/0415/21/1317564_109923795.shtml 因为本身从事存储行业,在工作中多次碰到用户有这样的要求:我的lin ...
- Tomcat监控—Status页面
原文:http://jingyan.baidu.com/article/925f8cb8f3d925c0dce05677.html 修改配置文件tomcat-users(该文件在Tomcat安装程序根 ...
- iOS中 xib自定义View在storyboard中的使用
1,创建UIView 的SubClass 命名为MyView 2, new一个名为MyView的xib p1 3,配置xib的属性 p2 4,为View 添加背景色,添加一个按钮并定制按钮约束,这里我 ...
- easyui 消息提示框
1.浏览器消息提示框 浏览器弹出框,可以在浏览器设置中被屏蔽掉,导致效果失效 alert() 2.easyui 框架提供的消息框 easyui 框架自带的消息框,不可以被屏蔽. $.messager. ...
- ylbtech-LanguageSamples-OLEDB
ylbtech-Microsoft-CSharpSamples:ylbtech-LanguageSamples-OLEDB 1.A,示例(Sample) 返回顶部 “OLE DB”示例 本示例演示了如 ...
- [转]SQL Server 2005 Integration Services (SSIS) (3) - Business Intelligence Development Studio
本文转自:http://blog.csdn.net/me_online/article/details/1546281 三,SQL Server Integration Services 开发环境– ...