Reputation: 16211
My Problem
I have a custom zip file with the extension .trap
which I email to myself and receive in my Gmail account on my android phone.
I need to be able to say that my application can open this file and handle it accordingly. I have looked all over and there are many variations out there but none seem to have worked for me. I did also see that Android doesn't allow the opening of .zip
files.
Here are my intent filters I add to my android manifest.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.trap" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/trap" />
</intent-filter>
<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:pathPattern=".*\\.trap" />
</intent-filter>
NB: For the MIME type I have also tried */*
which doesn't work and just /
which stops the app from launching.
My Questions
Thanks in advance
Upvotes: 0
Views: 2087
Reputation: 16211
The other answers are both good answers and may work for someone. They definitely helped me understand it more so thumbs up to them.
The method that worked for me however is shown below.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.trap" />
<data android:pathPattern=".*..*..*..*..*..*.trap" />
<data android:pathPattern=".*..*..*..*..*.trap" />
<data android:pathPattern=".*..*..*..*.trap" />
<data android:pathPattern=".*..*..*.trap" />
<data android:pathPattern=".*..*.trap" />
<data android:pathPattern=".*.trap" />
</intent-filter>
I hope this helps someone.
Upvotes: 2
Reputation: 14274
Because GMail acts as a content provider, you'll need to add the content
scheme, like so:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/*"
host="*"
android:pathPattern=".*.trap"
android:scheme="content" />
</intent-filter>
Upvotes: 1
Reputation: 1007296
Can android open zip files from an email?
Only with the help of an app.
How to specify that my application is able to handle the opening of this file type.
This may work:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/trap" />
</intent-filter>
This assumes that the email client sending this message uses your custom MIME type (which, BTW, probably ought to be in the vnd.
namespace).
Your existing filters assume that the attachment is a file or an HTTP request, whereas Gmail attachments present themselves to you via a ContentProvider (content:// scheme).
You can have BROWSABLE
in there if you want as well as DEFAULT
, if you think that you will also be downloading application/trap
files via a Web browser.
Upvotes: 1