I am trying to open an activity from a class that extends Service, when the app is not in foreground/not being used. I noticed that the activity was not opening.
After researching, I discovered that I need to manually grant the permission, “Display popup windows while running in the background” in the app settings. The permission, SYSTEM_ALERT_WINDOW, only grants access to “Display popup window”. I am unsure how to check or ask the user for this permission. Do apps like Whatsapp have this permission checked by default?
To check if the app has the “Display popup windows while running in the background” permission, use the
Settings.canDrawOverlays(Context context) method. If it returns true, the permission is granted. If it returns false, you can request the permission by showing an AlertDialog to the user with an intent to the app settings page using
Apps like Whatsapp have this permission checked by default as they are pre-installed system apps and have the necessary permissions granted by default.