Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PRO

Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PRO

Android Q (Android10) 中,MediaProjection必须在前台服务中进行
参考链接:https://blog.csdn.net/qq_36332133/article/details/96485285

关键是要声明权限

  

然后以
startForegroundService(service);的方式启动服务
同时不要忘记startForeground(id, notification);设置服务,
不然会报异常

Context.startForegroundService() did not then call Service.startForeground()

你可能感兴趣的:(Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PRO)