my target scenario: User opens an attachment in his/her preferred email-app. My app is proposed to open/view the attachment, user chooses my app, my app opens the attachment-uri via ContentResolver.openInputStream(uri) and reads from it.
This normally works great. It has come to my attention though, that several email-apps now require special permissions like: com.fsck.k9.permission.READ_ATTACHMENT, com.android.email.permission.READ_ATTACHMENT, com.motorola.blur.service.email.Permissions.INTERACT, etc.
I think it is bad design to add a uses-permission-tag for each and every email-app on the market. Is there a better way to be able to generally read attachments?
Furthermore – even if I decide to continuosly add uses-permissions to my app with every release, I run into another problem: If the app that requires the permission is installed after my app, my app will not have the permission, because at the time of my apps installation it wasn’t known to the packagemanager that such an permission even existed.
So – do I really have to instruct my users to reinstall my app if they decide to switch to a new email-app that my app already has uses-permissions for? Just because my app was first on their system??
Any help would be greatly appreciated. Thanks for reading!!
I am now able to remove all these Custom-Permissions from my app and still able to read attachments.
Turns out I was doing everything right, except for one little thing…
… I was handling reading the attachment in two Activities. The first
Activity– my mainActivity– is responsible for gathering theIntent-information and selecting/preparing a database for storing the to-be-imported data. The secondActivityis actually reading from theInputStreamobtained viaContentResolverand importing into the database.Turns out that
FLAG_GRANT_READ_URI_PERMISSIONonly grants permission to the recipient of theIntent. As I was passing on theUriof the attachment to a secondActivityit could not be read there anymore – only by granting my app several customPermissions, a solution I can’t really recommend as described above.My solution now is to read all the data in my first
Activity, storing it in a temporary file and passing this file-Urito my secondActivity. Of course now I have to care about how long copying takes, maybe display progress dialogs and determine where I can find enough space for my temp, accessing the original-Uriseemed quite a lot easier.