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其 ...
随机推荐
- 【树形dp】hdu6035 Colorful Tree
非常棒的题解,我就不复述了:http://blog.csdn.net/Bahuia/article/details/76141574 O(n) #include<cstdio> #incl ...
- LeetCode 771. 宝石与石头(java)
给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符都是字母 ...
- JavaScript的深拷贝与浅拷贝
深拷贝和浅拷贝是在面试中经常遇到的问题.今天在这里总结一下. 深拷贝与浅拷贝的问题,涉及到JavaScript的变量类型,先来说说变量的类型,变量类型包括基本类型和引用类型. 基本类型:Undefin ...
- Codeforces Round #339 (Div. 1) C. Necklace 构造题
C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...
- 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 ...
- 【个人专用&入门级】LAMP一键安装包
最近自学了下Shell编程,也算是入门吧!按照如下教程,编译安装了LAMP(Apache-2.4.6 + MySQL-5.5.25 + PHP-5.3.27) CentOS6.3编译安装LAMP(1) ...
- class"org.apache.commons.dbcp.BasicDataSource"not found出错的解决办法
法1:在项目上右击build path->configure build path..->add library..->MyEclipse Libraries选中Spring 2.0 ...
- 报错:configure: error: no acceptable C compiler found in $PATH
运行以下命令报错: ./configure 错误: checking whether to enable maintainer-specific portions of Makefiles... ye ...
- 【笔记】js原生方法 在元素外部或内部实现添加元素功能(类似jq 的 insert 和 append)
介绍的这个方法是:insetAdjacentHTML() 方法 此方法接收两个参数: 第一个参数必为下列值: beforebegin:在调用的元素外部的前面添加一个目标元素 afterend:在调用元 ...
- 不输入sudo使用docker
系统是debian系 安装: sudo apt install docker.io 将当前用户加入‘docker’组: sudo gpasswd -a ${USER} docker 刷新权限: su ...