1

Is there a way to detect programmatically that another app is drawing over my app?

Or is there a way to block this?

Or is there a way to detect that non-system apps have the SYSTEM_ALERT_WINDOW permission?

I have an activity that may not be used when another app is drawing over mine for safety reasons.

Doesn't something like this exist for games etc.?

Sam Debruyn
  • 928
  • 1
  • 8
  • 22

2 Answers2

0

You can use application lifecycle methods, as another app comes in the foreground your will execute onPause and then eventually will go to the background. I have not tried it but this must be the case. Better first go through the application lifecycle methods and then you can play around.

Niki
  • 1,566
  • 1
  • 19
  • 36
0

You can use

packageManager.checkPermission(android.Manifest.permission.SYSTEM_ALERT_WINDOW,"com.example.yourpackage")

which returns PERMISSION_GRANTED or PERMISSION_DENIED

The possible solution is to check it by iterating by getting the package name of all the available applications inside the device.

For devices with targetVersion less than 23 by default PERMISSION_GRANTED will be there.

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77