yrom / ScreenRecorder

Implement screen capture without root on Android 5.0+ by using MediaProjectionManager, VirtualDisplay, AudioRecord, MediaCodec and MediaMuxer APIs
1.86k stars 528 forks source link

Crashed after change targetSdkVersion to 29 #41

Open dynamicfire opened 5 years ago

dynamicfire commented 5 years ago

Logcat: 2019-07-30 15:04:57.215 909-3862/? E/InputDispatcher: Window handle Window{7faca60 u0 Sys2003:com.android.systemui/com.android.systemui.media.MediaProjectionPermissionActivity} has no registered input channel 2019-07-30 15:04:57.233 28983-28983/? D/AndroidRuntime: Shutting down VM 2019-07-30 15:04:57.241 28983-28983/? E/AndroidRuntime: FATAL EXCEPTION: main Process: net.yrom.screenrecorder.demo, PID: 28983 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {net.yrom.screenrecorder.demo/net.yrom.screenrecorder.MainActivity}: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION at android.app.ActivityThread.deliverResults(ActivityThread.java:4843) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4884) at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7343) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933) Caused by: java.lang.SecurityException: Media projections require a foreground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION at android.os.Parcel.createException(Parcel.java:2071) at android.os.Parcel.readException(Parcel.java:2039) at android.os.Parcel.readException(Parcel.java:1987) at android.media.projection.IMediaProjection$Stub$Proxy.start(IMediaProjection.java:231) at android.media.projection.MediaProjection.(MediaProjection.java:58) at android.media.projection.MediaProjectionManager.getMediaProjection(MediaProjectionManager.java:104) at net.yrom.screenrecorder.MainActivity.onActivityResult(MainActivity.java:148) at android.app.Activity.dispatchActivityResult(Activity.java:8110) at android.app.ActivityThread.deliverResults(ActivityThread.java:4836) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4884)  at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:214)  at android.app.ActivityThread.main(ActivityThread.java:7343)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:933)  Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.media.projection.MediaProjectionManagerService$MediaProjection.start(MediaProjectionManagerService.java:476) at android.media.projection.IMediaProjection$Stub.onTransact(IMediaProjection.java:135) at android.os.Binder.execTransactInternal(Binder.java:1021) at android.os.Binder.execTransact(Binder.java:994)

dynamicfire commented 5 years ago

Android Q似乎要求mediaprojection需要在services中进行 https://developer.android.com/reference/android/content/pm/ServiceInfo https://blog.csdn.net/qq_36332133/article/details/96485285

dynamicfire commented 5 years ago

另:在Android Q下录屏时没有弹出通知

yrom commented 5 years ago

本来 mediaprojection 就应该在 service 中使用,这里只是demo,没用service

dkshin commented 4 years ago

same issue....

target sdk version : 29 my device : Android10

TapasKumarBehera commented 4 years ago

same issue....

target sdk version : 29 my device : Android10