With the new privacy changes in effect with Android Q, it is now mandatory for any app using MediaProjection
api to specify android:foregroundServiceType attribute
Don't you forget to add permission
into AndroidManifest.xml
?
UPDATE
Make sure you call startForeground()
before getMediaProjection()
!
The best solution is to call startForeground()
from onCreate()
without any conditions, displaying some sort of default messages in notification. Then you can execute your logic and call NotificationManager.notify()
with updated notification at any time.