Gmail attachment and user extension

I am currently working on an Android application that reads a file with a user extension. One of the required features is that the application should be offered by gmail when the user receives mail with the .ourextension attachment.

I did some research and found that the Gmail client on Android does not rely on the extension, because the proposed file does not have an extension in the data about the launched intention. It relies only on the mime type specified by the mail client.

The problem is that our user file is not found in the same way between email clients. For example, if I send my user file to my gmail web page, the mime type is defined as application / octet-stream. If my friend is sent using Apple mailbox software, it shows up as text / xml (which would be nice). And on another Evolution email client, the mime type is text / plain ...

Our application cannot handle all of these types! Otherwise, this would be suggested for each type of attachment ...

Is there any solution for this?

+6
source share
4 answers

Solution for opening a file with a user extension tested with gmail <4.2, gmail 4.2, Google Drive and the file browser

Code for sending the file:

sendIntent.setType("application/calc1"); 

Intent-filter:

  <!-- Filter to open file with gmail version < 4.2 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="application/calc1" /> <data android:pathPattern=".*\\.calc1" /> <data android:host="*" /> </intent-filter> <!-- Filter to open with file browser or google drive --> <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=".*\\.calc1" /> <data android:host="*" /> </intent-filter> <!-- Filter to open file with gmail version 4.2 --> <!-- Save file first with "save" button otherwise gmail crashes --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="application/octet-stream" /> <data android:pathPattern=".*\\.calc1" /> <data android:host="*" /> </intent-filter> 
+3
source

You can get this to work from gmail, although it takes a lot of effort to figure out all the problems.

Important intent data

 act=android.intent.action.VIEW dat=file:///mnt/sdcard/Download/Availability Focus.inform typ=application/octet-stream flg=0x80001 cmp=air.com.extension/.AppEntry 

An intent filter that was able to capture it (some notes below)

  <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="file" android:pathPattern=".*\\.inform" android:mimeType="application/octet-stream"/> <data android:scheme="content" android:pathPattern=".*\\.inform" android:mimeType="application/octet-stream"/> </intent-filter> 

Both content and file formats are required. Without a CONTENT scheme, gmail will ignore your filter. This seems like a mistake. Without the FILE scheme, gmail will throw an error stating that it does not know which application starts with the intent.

 07-19 15:38:19.160: ERROR/Gmail(2220): Coun't find Activity for intent 

When using both schemes, the application receives the intention for both downloaded and previewed files. They must be handled differently.

+2
source

Edit: This answer is 3 years. I did not have time to check other answers, but mine is clearly out of date, so please see the rest of the answers on this topic!

I did not find any solutions, the only way to work with the mime type, so you must pray that your application is recognized with the known mime type and handle this. This means that you will interfere with another application if your file is known as html, for example.

You need to handle the case when the file is not read by your application and displays a pop-up window to notify the user that you cannot read the file.

Perhaps in a year or two, Gmail will provide a good api ...

By the way, the latest version of gmail adds a download button that you must process to avoid crashes, it works by creating a new file with uri.

0
source

You can still map the extension for gmail

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

Make the change for mime type equal to / and itll will only match with extension

0
source

Source: https://habr.com/ru/post/890215/


All Articles