Use getType() on the Intent used to start your activity to find out
the MIME type of the document.

On Tue, Feb 22, 2011 at 5:35 PM, Jonathan Nalewajek
<[email protected]> wrote:
> I am having a few issues with sharing email attachments....
>
> My activity has several intent filters that handle multiple MIME-types
> (pdf, doc, xls, etc.). If I get an email with a .pdf attachment, I can
> share it with my activity, but inside my activity, I am not sure how
> to get the MIME type of what is being shared. I can get the
> inputstream, but I get a permission issue when trying to access
> getType(uri).
>
> Here is my code to get the input stream:
>
> Intent shareIntent = getIntent();
> InputStream is =
> getContentResolver().openInputStream(shareIntent.getData());
>
> If I then print out the value of is.available(), it appears to be the
> appropriate size. In other words, the data is there.
>
> However, if I call:
> getContentResolver().getType(shareIntent.getData());
>
> I get the following exception:
> ERROR/DatabaseUtils(7944): java.lang.SecurityException: Permission
> Denial: reading com.android.email.provider.EmailProvider uri
> content://com.android.email.provider/attachment/48 from pid=8048,
> uid=10114 requires com.android.email.permission.ACCESS_PROVIDER
>
> The problem is, if I simply have the byte array, I have no idea what
> extension the final file should be.
>
> I know there are apps that can get not only the MIME-type, but can get
> the entire filename. For example, if I try to open a pdf from my
> inbox, and I open it with QuickOffice, I can see the filename at the
> top of quickoffice.
>
> Can someone please explain to me what I am doing wrong, and at least
> point me in the right direction? Opening email attachments in another
> application seems like such a simple feature...
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.4 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to