【问题标题】:Why isn't my app on the list of apps to open pdf files only?为什么我的应用程序不在仅打开 pdf 文件的应用程序列表中?
【发布时间】:2013-11-25 18:30:21
【问题描述】:

我有一个 pdf 阅读器应用程序,旨在提供选择选项以在应用程序内打开系统中的任何 pdf 文件。我已经参考了以下链接: Why isn't my app on the list of apps to open txt file? 我只希望我的应用程序在仅打开 pdf 文件的列表中,但现在我的应用程序在每种类型文件的列表中。我确实有,但我想知道是否应该指定 mimeType。我应该怎么做才能将我的应用程序限制为仅出现在打开的 pdf 文件列表中?

感谢高级, AA。

【问题讨论】:

  • Hey Arushi .. 希望您能在这里找到解决方案.. stackoverflow.com/questions/8055859/…
  • 以上代码并不限制我的应用程序只能打开 pdf 文件。我的代码。 打开所有类型的文件。我只想通过我的应用程序打开 pdf 文件。谢谢。
  • okie,对不起……我正在为此做研发。

标签: android


【解决方案1】:

我曾经写过一个类似的应用程序。我发布了我的 AndroidManifest.xml 片段供您参考:

<activity
    android:name=".OpenFileActivity"
    android:configChanges="orientation|keyboardHidden"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" >
        </action>

        <category android:name="android.intent.category.DEFAULT" >
        </category>
        <category android:name="android.intent.category.BROWSABLE" >
        </category>

        <data
            android:mimeType="application/pdf"
            android:scheme="file" >
        </data>
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" >
        </action>

        <category android:name="android.intent.category.DEFAULT" >
        </category>
        <category android:name="android.intent.category.BROWSABLE" >
        </category>

        <data
            android:mimeType="application/pdf"
            android:scheme="content" >
        </data>
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" >
        </action>

        <category android:name="android.intent.category.DEFAULT" >
        </category>
        <category android:name="android.intent.category.BROWSABLE" >
        </category>

        <data
            android:host="*"
            android:pathPattern=".*\.[pP][dD][fF]"
            android:scheme="file" />
    </intent-filter>
</activity>

【讨论】:

  • 以上代码并不限制我的应用程序只能打开 pdf 文件。我的代码。 打开所有类型的文件。我只想通过我的应用程序打开 pdf 文件。谢谢。
  • 您可以将 mimeType 指定为“application/pdf”。
  • 我尝试将 mimeType 从“/”更改为“application/pdf”,但仍然可以通过我的应用程序打开文本文件。
  • Manifest 文件中是否还有其他意图过滤器?我在三星 S4 上试过。效果很好。
  • 在我的清单启动器屏幕中,意图过滤器为 和我的活动中的一个意图过滤器,即清单中的两个过滤器。
猜你喜欢
  • 2021-05-06
  • 1970-01-01
  • 2011-02-27
  • 1970-01-01
  • 1970-01-01
  • 2012-06-24
  • 1970-01-01
  • 1970-01-01
  • 2021-11-07
相关资源
最近更新 更多