Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Projection error #50

Open
Kalim06 opened this issue Apr 3, 2020 · 3 comments
Open

Media Projection error #50

Kalim06 opened this issue Apr 3, 2020 · 3 comments

Comments

@Kalim06
Copy link

Kalim06 commented Apr 3, 2020

Media projection requires a foreground service of type serviceinfo.

Getting this error when try to run the app. ANY IDEA?????

@yrom
Copy link
Owner

yrom commented Apr 8, 2020

Could you provide full stack trace or logs for this error?

@Kalim06
Copy link
Author

Kalim06 commented Apr 8, 2020

Thanks for replying. Your app has everything I need to work on my project. Will be great if you could help me out regarding this issue as I don't have that much knowledge regarding services.

2020-04-08 19:20:29.045 6085-6085/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myscreenrecorder, PID: 6085 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {com.example.myscreenrecorder/com.example.myscreenrecorder.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:4845) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886) 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:7356) 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:930) 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.<init>(MediaProjection.java:58) at android.media.projection.MediaProjectionManager.getMediaProjection(MediaProjectionManager.java:104) at com.example.myscreenrecorder.MainActivity.onActivityResult(MainActivity.java:186) at android.app.Activity.dispatchActivityResult(Activity.java:8110) at android.app.ActivityThread.deliverResults(ActivityThread.java:4838) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)  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:7356)  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:930)  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)

I cloned your project into a new project, works till Android 9, Giving this error for Android 10.

@yrom
Copy link
Owner

yrom commented Apr 9, 2020

When using MediaProjection target Android Q+, you must call MediaProjectionManager.getMediaProjection() in a forceground service of type ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PROJECTION.

<service
            android:name=".YourMediaProjectionService"
            android:enabled="true"
            android:exported="false"
            android:foregroundServiceType="mediaProjection" />

And don't forget the FOREGROUND_SERVICE permission:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

See
https://developer.android.com/reference/android/app/Service#startForeground(int,%20android.app.Notification)
https://developer.android.com/reference/android/Manifest.permission#FOREGROUND_SERVICE

related issue #41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants