0

I have an Android app that uses the SYSTEM_ALERT_WINDOW permission. I have a runtime check to make sure the permission is granted. When I sideload the app (for dev), it prompts me for the permission as usual. However, when a user installs it from the Play Store, the permission is (allegedly) automatically granted, but when they try to use it, an error is logged saying: Appop Denial: Accessing service ComponentInfo{<package>} from pid=<pid>, uid=<uid> requires appop SYSTEM_ALERT_WINDOW (basically saying the permission isn't granted). The weird part is, if the user goes to the app's settings and revokes and then permits the permission, it works. Any ideas why this is happening??

Kirollos Morkos
  • 2,503
  • 16
  • 22

1 Answers1

0

I have seen this same problem a number of times and found various answers to the problem. One solution that I recall had to do with the fact that when you request permission for SYSTEM_ALERT_WINDOW and then prepare a Toast after the result of the permissions, it would throw this same error. It has to do with the fact that the Android system perceives the toast as a secondary 'alert' and throws the above exception when it happens in succession.

If you are creating any type of Toast after the result check of the permission (usually in the onRequestPermissionsResult method), try removing it and see if you have the same issue.

PGMacDesign
  • 6,092
  • 8
  • 41
  • 78
  • I only prepare a toast if the permission was not granted, and since it is granted automatically, this never happens. Do you know anything else that might cause the error? – Kirollos Morkos Feb 11 '18 at 19:38
  • Just for testing's sake, if you completely remove all toasts from the code in question (even the one for permission deny), does this issue still persist? – PGMacDesign Feb 11 '18 at 19:59
  • I just tried removing all the toasts, still no luck – Kirollos Morkos Feb 11 '18 at 21:42
  • Try looking at these 2 links: https://stackoverflow.com/questions/35453759/android-screen-overlay-detected-message-if-user-is-trying-to-grant-a-permissio and https://stackoverflow.com/questions/42774824/how-do-i-determine-which-app-is-causing-the-screen-overlay-detected-error Just to see if either of those have similar enough problems that help you to identify an answer. Apologies for not being able to help further! – PGMacDesign Feb 11 '18 at 22:16