Using "mediaprojection" I was able to capture the current screen from a background service. The sdk api is 25, Android 7.1.2, and I checked it with an emulator running with BlueStacks without rooting and my mobile phone without rooting. But when I test it with BlueStacks and another emulator, Nox, I get a black screen. The same code and only in the Knox emulator without rooting the same code is black screened in the result.
Could the results be different depending on the emulator? Do you have a "mediaprojection" application running in a background service to test this case?