Android Intent 过滤器

标签 android

我已经编写了下面的 Intent 过滤器来使用我的应用程序打开一个文本文件。它似乎有效,但只是有时有效。例如,如果我通过电子邮件发送一个文本文件,如果我选择从邮件打开,则不会显示我的应用程序。如果我先选择保存,然后打开,我的应用程序将被显示。与保管箱类似的经历,如果我尝试从保管箱打开,我的应用程序将不会被列为能够打开但是如果我从保管箱导出到 sd 并使用文件管理器打开它,我的应用程序会被列出并且作品。

<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="http" android:host="*" android:pathPattern=".*\\.txt" />
      <data android:scheme="https" android:host="*" android:pathPattern=".*\\.txt" />
      <!--  <data android:scheme="content" android:host="*" android:pathPattern=".*\\.txt" /> -->
  <data android:scheme="file" android:host="*" android:mimeType="*/*" android:pathPattern=".*\\.txt" />
   </intent-filter>

最佳答案

Dropbox 和电子邮件应用程序可能使用内容提供程序并且与 pathPattern 不匹配。通常内容提供者不包含文件扩展名,但会使用 mime 类型来指示正在打开的文件类型。如果您打算打开任何 text/plain 文件,而不仅仅是那些具有 .txt 扩展名的文件,那么您最好离开 pathPattern 完全关闭。

<intent-filter>
      <data android:mimeType="text/plain" />
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

关于Android Intent 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12197298/

相关文章:

android - NestedScrollView 将高度设置为两个布局之间的空间

android - 自定义抽屉导航的涟漪效应

java - 在 logcat 中显示数组值

java - 如何通过按钮OnClick保存Canvas图像?

Android Studio 3.0 生成平面依赖关系树,那么我该如何阅读它

java - 在循环中一个一个地创建套接字数量

java - 当我按住直到松开然后停止时,如何进行连续工作?

java - Android ArrayAdapter 构造函数不采用通用对象?

安卓 setImageResource NullPointerException

java - Android - 移动布局或动画项目到购物车