Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PRO
Android Q (Android10) 中卖毁,MediaProjection必須在前臺(tái)服務(wù)中進(jìn)行
參考鏈接:https://blog.csdn.net/qq_36332133/article/details/96485285
關(guān)鍵是要聲明權(quán)限
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
然后以
startForegroundService(service);的方式啟動(dòng)服務(wù)
同時(shí)不要忘記startForeground(id, notification);設(shè)置服務(wù)伞梯,
不然會(huì)報(bào)異常
Context.startForegroundService() did not then call Service.startForeground()