【问题标题】:Saving File and Opening with Android App使用 Android 应用程序保存和打开文件
【发布时间】:2014-02-21 00:32:26
【问题描述】:

我正在将二进制文件保存到具有自定义扩展名的文件中,例如 .custom。如何将其保存为特定的 mime 类型?我希望调用我的应用程序来打开该自定义文件。在清单中,我使用 / 作为 mimeType,但即使在点击图像时也会调用该应用程序。我使用了 octet-stream,但该文件没有被识别并且应用程序没有被打开。我只想保存一个带有自定义扩展名的二进制文件,操作系统会在遇到此文件时调用我的应用程序。

 <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:scheme="file" />
        <data android:mimeType="application/octet-stream" />
        <data android:pathPattern=".*\\.test" />
        <data android:host="*" />
   </intent-filter>

【问题讨论】:

    标签: android mime-types file-extension file-association file-browser


    【解决方案1】:

    最后,经过几次查看后没有答案,我想通了。此链接上的帖子帮助我解决了我的问题。

    https://publish.illinois.edu/weiyang-david/2013/04/11/how-to-write-intent-filter-dealing-with-mime-type-problem/

    就是这个例子

     <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:scheme="http" />
        <data android:host="*" />
        <data android:pathPattern=".*\.pdf" />
      </intent-filter>
    

    我将方案替换为“文件”并替换为我的 pathPattern。删除 mimeType 是解决我的问题的关键。文件浏览器现在建议使用我的应用打开自定义文件。

    【讨论】:

      猜你喜欢
      • 2013-05-18
      • 1970-01-01
      • 1970-01-01
      • 2013-07-18
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多