Android添加文件打开方式,将你的app加入打开方式
2018-03-05 17:24
519 查看
如何让自己的软件出现在打开方式的列表中呢? 通过设置AndroidManifest.xml文件即可:<activity android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTask" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:mimeType="text/plain"></data>
</intent-filter>
</activity>添加第二个<intent-filter>,这样你的应用程序就会出现在默认打开列表了
注意需要将mimeType修改成你需要的类型,文本文件当然就是:text/plain
还有其它常用的如:
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(同上,但主要用于表单提交时伴随文件上传的场合)
"intent.getDataString()"返回的就是所点击的文件路径,但是这里会有编码的问题,需要用decode处理一下:Intent intent = getIntent();
String action = intent.getAction();
if (intent1.ACTION_VIEW.equals(action)) {
Uri uri = intent.getData();
String str = Uri.decode(uri.getEncodedPath());}
str就是正确的路径
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<data android:mimeType="text/plain"></data>
</intent-filter>
</activity>添加第二个<intent-filter>,这样你的应用程序就会出现在默认打开列表了
注意需要将mimeType修改成你需要的类型,文本文件当然就是:text/plain
还有其它常用的如:
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(同上,但主要用于表单提交时伴随文件上传的场合)
Intent intent = getIntent(); String action = intent.getAction(); if(intent.ACTION_VIEW.equals(action)) {Log.v(intent.getDataString());}
"intent.getDataString()"返回的就是所点击的文件路径,但是这里会有编码的问题,需要用decode处理一下:Intent intent = getIntent();
String action = intent.getAction();
if (intent1.ACTION_VIEW.equals(action)) {
Uri uri = intent.getData();
String str = Uri.decode(uri.getEncodedPath());}
str就是正确的路径
相关文章推荐
- android 添加文件打开方式,找了很久终于找到了,收藏起来吧
- android 添加文件打开方式
- android开发仿照第三方app打开方式,如何将你的app显示在打开列表,并且将文件复制到你的app应用内
- Android开发: 获得某一个类型文件的打开方式
- android如何实现文件打开方式可供选择功能
- android文件打开方式
- 添加注册表,删除文件打开方式
- android自制的软件如何添加到打开方式
- Android 为某个App 添加/移除 启动快捷方式、书签快捷方式、应用市场快捷方式
- Android开发:获得某一个类型文件的打开方式
- 在Android 中设置xml 的文件的默认打开方式
- Android 文件打开方式
- XP中完美实现vista中快捷方式右键添加“打开文件位置”功能
- 程序不能添加进文件打开方式的注意点
- Android 文件打开方式
- Android 文件打开方式
- Microsoft Jet 数据库引擎打不开文件'……/App_Data/data.mdb'。 它已经被别的用户以独占方式打开,或没有查看数据的权限。
- 为快捷方式文件(lnk文件)右键菜单添加“打开所在文件夹”
- Android 文件打开方式
- Android 文件打开方式