Allow Application to Open a Custom Zip File From Gmail - android

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
Can android open zip files from an email?
How to specify that my application is able to handle the opening of this file type.
Thanks in advance

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.

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.

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>

Related

Associate App with .gpx extension - Intent filter Not working?

I want my application to be on the list to open .gpx from anywhere in the android environment. the none of the intent filters I tried didn't work, what do I need to add to make it work?
<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=".*\\.gpx" />
</intent-filter>

Issue with intent filter for opening a file in Android app

I'm trying to open any file with a .conf extension in my android app. Here's what I have in my AndroidManifest.xml:
<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:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.conf" />
</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="content" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.conf" />
</intent-filter>
But, when I tap on a .conf file in the Downlaods folder, it says "Can't open file."
Here's what I get when I use Intent Intercept:
What am I doing wrong?
Remove:
<data android:host="*" />
from both <intent-filter> entries and:
<data android:pathPattern=".*\\.conf" />
from the content one.
File extensions are not used much on Android. Starting with Android Q, files are not used much on Android. There is no requirement for a ContentProvider to put a file-like extension on a content Uri, as you can see from the Uri in your screenshot.
If you wish to support common Intent actions like ACTION_VIEW, your best bet is to save the file in a common meta-format (e.g., JSON, XML) with a file extension that matches, then have your <intent-filter> filter on the corresponding MIME type. You will need to deal with the possibility that the user chooses a file that was not created by your app, though technically you need to deal with that even with your custom extension.

What kind of intents should I use to save the bug report generated by android device

How can I get my app listed in the app chooser screen when sharing the bug reported generated by the android device. The bug report which can be generated using the USB debugging developers options. I have tried adding all the mime types in the data field. But still I am not able to see my app listed in the app chooser. The bug report generates a .zip file and a .png file. So, I have added application/* and image/* types.
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/zip" />
<data android:mimeType="audio/*" />
<data android:mimeType="image/png" />
<data android:mimeType="message/*" />
<data android:mimeType="multipart/*" />
<data android:mimeType="text/*" />
<data android:mimeType="video/*" />
</intent-filter>
I'm not 100% but I believe multiple <data ...> entries in your filter might be tripping you up. In order to debug I would start with a single <data android:mimeType="*/*" /> entry and confirm your application appears in the chooser.
If it does then you could check the Intent.getType() to determine what MIME type is actually being sent. From there you could add multiple filters for every expected type as shown in the documentation.
<activity android:name=".ui.MyActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
This appears to answer you question for you. Its long so I won't copy it here.
https://stackoverflow.com/a/16232417
android.intent.action.APP_ERROR Seems to be the intent filter you need to support to handle ANR/crash reports.

Android Register a file for download

A core part of my app is a nonstandard file type, in my case .crumb
The intent works properly for almost everything, except in the Gmail app.
I have confirmed that this intent works from file browsers, the Hotmail app, Skype, the aosp email app, etc.
But Gmail alone doesn't give the option to download.
Is there some kind of other file registration I'm supposed to do? Here is my intent filter:
<intent-filter android:priority="100">
<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="*/*" />
<data android:pathPattern=".*\\.crumb" />
<data android:host="*" />
</intent-filter>
I tried this intent but it don't work directly with skype. Skype save the file in download directory then, file can be downloaded with a file browser...
The solution for gmail is adding this second intent - filter (scheme is removing) :
<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:mimeType="*/*" />
<data android:pathPattern=".*\\.crumb" />
<data android:host="*" />
</intent-filter>

Android Respond To URL in Intent

I want my intent to be launched when the user goes to a certain url: for example, the android market does this with http://market.android.com/ urls. so does youtube. I want mine to do that too.
I did it! Using <intent-filter>. Put the following into your manifest file:
<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:host="www.youtube.com" android:scheme="http" />
</intent-filter>
This works perfectly!
You might need to allow different combinations of data in your intent filter to get it to work in different cases (http/ vs https/, www. vs no www., etc).
For example, I had to do the following for an app which would open when the user opened a link to Google Drive forms (www.docs.google.com/forms)
Note that path prefix is optional.
<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" />
<data android:scheme="https" />
<data android:host="www.docs.google.com" />
<data android:host="docs.google.com" />
<data android:pathPrefix="/forms" />
</intent-filter>

Categories

Resources