1

I've recently set my Android app up to receive Intents so it can be used to open attachments from email apps.

This works fine when my app is not already running when the Intent is created, but when my app is paused in the background, attempting to read the content from the URI causes SecurityExceptions to be thrown:

E/AndroidRuntime(28250): java.lang.RuntimeException: Unable to resume activity
{com.[...]/com.[...].Main}: java.lang.SecurityException: Permission Denial:
reading com.google.android.gm.provider.MailProvider uri content://gmail-ls/
notateme@gmail.com/messages/134/attachments/0.1/BEST/false from pid=28250,
uid=10205 requires com.google.android.gm.permission.READ_GMAIL, or
grantUriPermission()

E/AndroidRuntime(28250): Caused by: java.lang.SecurityException: Permission
Denial: reading com.google.android.gm.provider.MailProvider uri content://
gmail-ls/notateme@gmail.com/messages/134/attachments/0.1/BEST/false from
pid=28250, uid=10205 requires com.google.android.gm.permission.READ_GMAIL,
or grantUriPermission()

This web post suggests that the problem is that my activity has android:launchMode="singleTask" set, and that the way to solve the problem is to create an intermediary Activity to handle the Intent.

That fix does indeed work for me, but I'd like to understand why my original Activity appeared to have the permission to read from the URI when it was created to handle the Intent, but not when it was resumed to handle the Intent.

Could anyone explain this for me?

Rich
  • 7,348
  • 4
  • 34
  • 54

1 Answers1

1

You need to add READ_GMAIL permission in manifest.

<uses-permission android:name="com.google.android.gm.permission.READ_GMAIL" />

Refer this Manifest Permissions

Chirag Ghori
  • 4,231
  • 2
  • 20
  • 35
  • Thanks for the suggestion, but it doesn't answer my question. Why does it work fine *without* that permission, when my Activity is not already running? – Rich Feb 27 '14 at 11:39
  • because this permission only need when you attempting to read the content from the URI. so you get `SecurityExceptions` when you try to read the content from the URI. – Chirag Ghori Feb 27 '14 at 11:43
  • have you check after adding permission ? – Chirag Ghori Feb 27 '14 at 11:44
  • Again, I can successfully read the content from the URI *without* adding the permission, so long as my app is not running before I attempt to open the attachment from the email. I want to know why this works, but it doesn't work if my app is paused in the background. – Rich Feb 27 '14 at 14:52