PermissionsDispatcher: Allow multiple methods to use same @NeedsPermission (and avoid DuplicatedValueException)

Say that you have multiple methods that each require the identical permission to, say, write to external storage. Because you don’t know what the user is going to do, you want to make sure that if either method is called, the appropriate permissions is checked and a request is made to the user…

So— you annotate with @NeedsPermission("android.permission.WRITE_EXTERNAL_STORAGE") on each. But now, you get one of these:

Error:Execution failed for task ':compileDebugJavaWithJavac'. > permissions.dispatcher.processor.exceptions.DuplicatedValueException: [android.permission.WRITE_EXTERNAL_STORAGE] is duplicated in interface permissions.dispatcher.NeedsPermission

Unfortunately, the documentation for the new runtime permissions kind of assume that there’s only one occasion in which you’ll be asking for a permission-- you can set various request codes in @onRequestPermissionResult– supposedly one per permission, right? But in the above case you’d have to set them to account for each method that might be using each permission. And handle the result for every possible combination of methods/permissions/responses right there.

Sigh. This could easily become a logistical nightmare. Maybe PermissionsDispatcher could make it easier by allowing more than one method to use @NeedsPermission for the same permission(s) and do the right thing?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

I have also run into this problem, with multiple methods needing the same permission, so I would really appreciate, if you would prioritise this.

Thanks 👍