android - 使用我的 Android 应用程序注册 FileExtension

标签 android file types mime

我有一个只包含“abcdefg”这样的文本的文件,它可以从网上下载或从本地存储卡打开。 我的想法是给这个文件一个独有的扩展名,比如 .myfile 并在我的应用程序中注册“.myfile”。我在谷歌上找到了一些解决方案,但没有一个对我有帮助。似乎文件扩展名无关紧要,只有内容类型才重要。 但是,我想我必须在我的 android list 中使用 mimeType 和 pathPattern...[...] 注册一个 intent-filter。 但我到底需要做什么?

    <intent-filter>

    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.EDIT" />
   <category android:name="android.intent.category.DEFAULT" />
<data
android:mimeType="application/myfile"
android:host="*" 
android:pathPattern=".*\\.myfile"/>
   </intent-filter>

这对我不起作用:(

最佳答案

  <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
 <data           android:host="*"
                android:mimeType="*/*"
                android:pathPattern=".*\\.myfile"
                android:scheme="file" />

这行得通!

关于android - 使用我的 Android 应用程序注册 FileExtension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23251435/

相关文章:

android - 从广播接收器更新 ui

file - 如何在 MATLAB 中将数据保存在 .txt 文件中

java - 在 Scala 中使用通用基元数组

typescript - 如何根据字段值省略联合类型

java - 如何用Java从文本文件中读取格式化数据

c++ - 如何在 C++ 中存储带单位的数字数据?

Android getTargetFragment().getView() 返回 null

java - 从启动画面到实际的应用程序。不幸的是APP已停止

android - 如何在应用程序中构建小程序(又名tinyapp)框架?

c - 为什么 fflush() 不被认为是安全的?