Issue
I have an app that generates custom file types (.sor). Inside the app I have a feature to send an email with one of these files attached. I also have an intent filter to allow the app to show up in the list of apps that can open this type of file. This allows me to (sometimes) open the file with the app right from the users email client on the phone.
However, this only works when the email comes from a PC email client, and will not work when the email is received from a phone. For example, if I generate one of these .sor files and then use my app to send an email to my own email account I will receive the email on my phone but will not be able to open the attachment with my app... BUT, if I send the email to the same account and open it on my PC (with Thunderbird) instead of on the phone and then either forward it or send it as a new email to my phone I will be able to use the same email app on the phone to open the attachment with my app... I'm only talking about one email account here, the only difference is where the email was sent from, my phone or my windows 7 PC.
The only thing I can think of is that when I send the email from the phone a different mime-type is being embedded into the attachment than when I send it from Thunderbird on my PC... I specify the mime type as "application/octet-stream" when I send out the email from my app, and I have an intent filter that looks for this mime type... but it does not work correctly.
My intent filter:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/octet-stream" />
<data android:scheme="file" />
</intent-filter>
The intent that I pass to the phones email client when sending the file in an email attachment from the phone:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("application/octet-stream");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + fullPathString));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "FiberDroid OTDR Trace File: \"" + ContextMenuFileName + "\"");
sendIntent.putExtra(Intent.EXTRA_TEXT, "This e-mail was sent from the TTI FiberDroid Android application.");
startActivity(Intent.createChooser(sendIntent, "Select E-Mail Application"));
Again, the sending of the email with the file attached works correctly... and if I email the same file back to the phone from a PC email client (such as outlook or thunderbird) then I am able to open the file with my application directly from the phones email app. The problem is, if I open the email on the phone without going through my PC as a middleman I cannot open the attachment, the only option I am given is "Save to SD Card"...
So to recap, I have 2 emails on my phone that are identical, with the same file attached and both originally sent from my application to the same account (both received from the same account also), but the attachment in the one that went through my PC as an unnecessary middleman works correctly, and the one sent and received directly from my phone does not.
Any ideas? Thank you in advance.
Solution
I've solved this, mostly by shooting in the dark and without really understand WHY what I did solved it, but here is what I have for my intent filters in the manifest now, where ".sor" is the extension of my custom file type. This works with all email and file management apps that I have tried, including K-9 mail and Astro:
<!-- For email attachments -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/*" host="*" android:pathPattern=".*.sor" android:scheme="content" />
</intent-filter>
<!-- For file browsers -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="application/*" host="*" android:pathPattern=".*.sor" android:scheme="file" />
</intent-filter>
Answered By - CHollman82
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.