开发者

Register file type for app does not work correctly

I am using the following intent filter for my app.

<intent-filter> 
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="开发者_StackOverflow中文版android.intent.category.BROWSABLE" />
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.etxt" />
</intent-filter>

But to my surprise, the app now wants to open other types too, like apk files. What is my mistake?


Try

 <data android:pathPattern=".\\*.etxt" />

not <data android:pathPattern=".*\\.etxt" />

and please let me know if it works


I found this

"These attributes are meaningful only if the scheme and host attributes are also specified for the filter."

so you should have scheme and host if you want to use android:pathPattern

it is on the official documentation http://developer.android.com/guide/topics/manifest/data-element.html

Note this: If a scheme is not specified for the intent filter, all the other URI attributes are ignored

so you will have to add scheme and host


I think I found a solution. At least, it works for Dropbox now.

<intent-filter> 
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="file"/>
    <data android:host="*"/>
    <data android:mimeType="application/*"/>
    <data android:pathPattern=".*\\.etxt" />
</intent-filter>


This has been some time ago, but I still do not have a proper solution. The solution in the answer below works in Dropbox, but will not open the app in Google mail, or in any file manager. And yes, the path pattern is correct.

I tried with mimeType text/* only, nothing else. This will not work, unless you name the files with extension *.txt. I cannot go this way, since in Windows there is a counterpart, which registers *.etxt for the files.

Then I tried with an additional scheme "content". This works for Google mail if I select a general mimeType, but will offer the app, if the user clicks on the new mail icon in the status bar. So it is too general.

In short, I did not find a way to solve this. It seems to depend on the way, the file managers and mail programs form an intent, and this is not predictable. I guess, it is simply an omission in the Android system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜