本文介绍了的Andr​​oid如何创建意图过滤器进行自定义的文件扩展名,不使它成为一个选择器的一切在手机上的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到的在这里无数的答案如何创建一个意图过滤器为自定义文件扩展名,但他们都不是回答我的问题:

I have seen numerous answers on here about creating an intent filter for a custom file extension, but none of them seem to be answering my question:

我有一个意图过滤器的工作原理,现在...当我浏览我的文件,或者当我从电子邮件附件中打开它,我的应用程序将出现在列表中。文件本身具有tgtp自定义扩展,但它基本上是一个XML文件。

I have an intent filter that works right now... when I browse for my file or when I open it from an email attachment, my app will appear in the list. The file itself has a custom extension of "tgtp", but it is basically just an xml file.

我遇到的问题是,虽然这个意图过滤器的工作原理,它也似乎我的应用程序添加到每个选择器的在我的手机每一个类型的文件。一个例子是,如果我清楚我的联系人应用程序的默认值,然后单击我的联系人之一,它说我的应用程序可以打开它。

The problem I am having is that although this intent filter works, it also appears to add my app to every chooser for every type of file on my phone. An example would be if I clear my contacts app defaults and click on one of my contacts, it says my app can open it.

我已经试过许多意图过滤器有不同的方案,MIME类型等的不同组合......有的还是让我打开该文件,如果我浏览一个文件浏览器,但我特别需要能够打开电子邮件附件并打开的文件浏览器。我还没有找到一个意图过滤器(S),让我做,没有让我的应用程序适用于所有其他的意向选择器。

I've tried dozens of different combinations of intent filters with different schemes, mime types, etc... and some still let me open the file if i browse with a file browser, but I specifically need to be able to open email attachments and open as file browser. I am yet to find an intent filter(s) that allow me to do that without making my app available for every other intent chooser.

下面是我目前的意图过滤器,用我的应用程序打开的一切:

Here is my current intent-filter that uses my app to open everything:

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

感谢你在前进

推荐答案

解决这个问题的唯一方法是增加计划主机属性你的意图过滤器:

The only way to solve this problem is add scheme and host attributes to your 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=".*\\.tgtp" />   
  <data android:host="*" />
</intent-filter>

这是因为在文档中说,安卓pathPattern 只能如果有定义的方案和主机。http://developer.android.com/guide/topics/manifest/data-element.html

That is because in documentation says that android:pathPattern only works if has an scheme and host defined.http://developer.android.com/guide/topics/manifest/data-element.html

希望它帮助。

这篇关于的Andr​​oid如何创建意图过滤器进行自定义的文件扩展名,不使它成为一个选择器的一切在手机上的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 07:03