如何添加自定义MIME类型? [英] How to add custom mime type?
问题描述
我要什么:为了能够通过邮件发送我的自定义文件,并与在Gmail中的preVIEW按钮我的应用程序导入或文件浏览器中打开时,它
我所知道的:我已经阅读了大量的自定义MIME类型处理程序,即Android不关心文件的扩展名等,但如何创造的MIME类型我自定义的文件吗?
的问题:我需要成为一个内容提供商?我只是想导入的文件(从备份)不提供任何内容。我见过有处理人的应用程序/ ABC的说法,它的正常工作,但如何增加这方面对我的文件myFile.abc和MIME类型?
一些方向如何注册/映射自定义MIME类型将appiciated! :)
<活动
机器人:名称=MainActivity
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen>
<意向滤光器>
<作用机器人:名称=android.intent.action.VIEW/>
<类机器人:名称=android.intent.category.DEFAULT/>
<类机器人:名称=android.intent.category.BROWSABLE/>
<数据机器人:主机={你的哑剧} .COM
机器人:计划=HTTP>
< /数据>
&所述; /意图滤光器>
< /活性GT;
<! -
机器人:计划=HTTP将让Android思考,多数民众赞成这是一个链接
- >
现在,当你收到短信的文字:在网络上的http // {您的哑剧} .COM
或点击链接与这段文字,你的活动(MainActivity)将运行。
您还可以添加参数:
文本=HTTP:// {您的哑剧} .COM /数= 111?;
然后在的onCreate()或onResume()方法,将添加:
意图intentURI = getIntent();
开放的我们的uri = NULL;
字符串receivedNum =;
Log.d(TAG,意图=+ intentURI);
如果(Intent.ACTION_VIEW.equals(intentURI.getAction())){
如果(intentURI!= NULL){
的uri = intentURI.getData();
Log.d(TAG,URI =+ URI);
}
如果(URI!= NULL)
receivedNum = uri.getQueryParameter(数字);
}
What I want: To be able to send my custom file by mail and import it with my application from the preview button in GMail or when opening it in a file browser.
What I know: I've read a lot of custom mime type handlers, that android doesn't care about file extension etc., but how to create the mime type for my custom file?
The question: Do I need to be a content provider? I just want to import files (from backup) not provide anything. I've seen people having handlers for "application/abc" saying it's working fine, but how to add that connection for my file "myFile.abc" and the mime type?
Some direction how to register/map custom mime types would be appiciated! :)
<activity
android:name="MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="{your mime}.com"
android:scheme="http" >
</data>
</intent-filter>
</activity>
<!--
android:scheme="http" will make android "think" thats this is a link
-->
Now, when you receiving a sms with the text "http://{your mime}.com"
or clicking link on the web with this text, your activity (MainActivity) will run.
You also can add parameters:
text = "http://{your mime}.com/?number=111";
Then in onCreate() or onResume() methods you'll add:
Intent intentURI = getIntent();
Uri uri = null;
String receivedNum = "";
Log.d("TAG", "intent= "+intentURI);
if (Intent.ACTION_VIEW.equals(intentURI.getAction())) {
if (intentURI!=null){
uri = intentURI.getData();
Log.d("TAG", "uri= "+uri);
}
if (uri!=null)
receivedNum = uri.getQueryParameter("number");
}
这篇关于如何添加自定义MIME类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!