Android自定义文件扩展名 [英] Android custom file extension

查看:95
本文介绍了Android自定义文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的Android应用程序能够通过蓝牙,电子邮件,WiFi Direct等(标准共享方法)共享文件.我想将我的数据解析为具有自定义扩展名的文件,然后通过某种共享方法(例如蓝牙)进行发送.收件人应该能够打开文件,然后我的应用程序启动并处理该文件.在互联网上搜索后发现很短,有人知道与此教程有关的任何好网站吗?或关于该主题的任何阅读材料?

I want my android app to be able to share files through bluetooth, e-mail, wifi direct etc... (the standard sharing methods). I want to parse my data into a file with a custom extension and send it through some sharing method say bluetooth. The recipient should be able to open the file then my app starts and handles the file. Searched around the internet and came up short, does anyone know any good sites with tutorials on this? Or perhaps any reading materials on this topic?

推荐答案

哈!一开始我也似乎干dry了,但是我的坚持终于得以实现.

Ha! I also initially seemed to come up dry on this search, but my persistence finally pulled through.

Android意向过滤器:将应用程序与文件扩展名关联

因此,他们在这里所做的是在manifest.xml文件中设置了一个 intent-filter ,这将使您的应用程序可以打开这些文件.就您而言,我怀疑您的代码看起来像这样

So, what they did on here is set up a intent-filter in the manifest.xml file that will enable your app to open those kinds of files. In your case, I would suspect that your code would look something like this

<intent-filter android:icon="drawable resource"
               android:label="string resource"
               android:priority="integer"> 
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="file" />
    <data android:host="*" />
    <data android:pathPattern=".*\\.CUSTOM_FILE_EXTENSION" />
</intent-filter>

我认为文件浏览器将能够从意图代码的那部分显示图标.但是我对此不太了解,所以不要在上面引用我:p

I presume that the file browsers will be able to get the icon to display from that part of the intent code. But I don't know too much about that, so don't quote me on it :p

编辑:此意图过滤器应位于活动/服务/接收者内部,该活动/服务/接收者将处理用户正在打开的自定义文件.

Edit: This intent filter should go inside the activity/service/receiver that is going to process the custom file the user is opening.

这篇关于Android自定义文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆