【问题标题】:my app is not showing in the list to open txt file in android 7.1.1我的应用程序未显示在在 android 7.1.1 中打开 txt 文件的列表中
【发布时间】:2017-09-20 08:58:14
【问题描述】:

您好,我正在开发一个应用程序来打开 txt 文件。当用户触摸 sd 卡上的 txt 文件时,我的应用程序应该显示在打开列表中。我的应用程序正在使用其他 android 版本的文件,但手机没有显示我的应用程序以列表方式打开。手机是通用手机gm5+。我不知道是因为手机还是安卓版本。这是我的清单

 <activity
        android:name=".ui.SplashActivity"
        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" />

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


            <data android:scheme="file" />
            <data android:mimeType="text/plain" />
            <data android:pathPattern=".*\\.txt" />


        </intent-filter>
    </activity>

感谢您的帮助。

【问题讨论】:

  • 发布 logcat 错误(如果有)
  • 没有生成日志猫
  • @SurendraKumar 很遗憾没用
  • 所以尝试重置应用偏好。可能有一个应用程序设置为文本文件的默认启动应用程序。转到“设置->应用程序->菜单(右上角3个点)->重置应用程序首选项”。

标签: android android-manifest intentfilter android-7.1-nougat


【解决方案1】:

检查你是否有权限

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>

试试这样的

<activity 
    android:name=".ui.SplashActivity"
    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"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="file" />       
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.txt" />
    </intent-filter>
</activity>

&lt;data android:scheme="file" /&gt; => 这定义文件必须是本地的,而不是来自 http 或 else

&lt;data android:mimeType="*/*" /&gt; => 匹配任何 mime 类型(具体使用 mimeType="text/plain")

&lt;data android:pathPattern=".*\\.txt" /&gt; => 您可以在此处指定要匹配的扩展名

intent-filter 可以包含多个动作根据需要还需要两个 intent-filter 工作

希望对你有所帮助

【讨论】:

  • 相同的代码只是替换 mimeType="text/plain" ?试试吧
  • 如果不行就试试这个我有另一个想法..先告诉我
【解决方案2】:

您也必须使用内容:

    <data android:scheme="content"
          android:mimeType="text/*" />

您也可以在这里使用 pathpattern 或指定其他 mimeTypes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-12
    • 2017-08-26
    • 2019-01-17
    • 2012-06-24
    • 1970-01-01
    • 2012-03-28
    • 2019-11-27
    • 1970-01-01
    相关资源
    最近更新 更多