Hey everyone, I’m facing a big problem with my app that uses flutter_webrtc for screen sharing. It keeps crashing on Android 14 devices. Here’s what’s going on:
The app crashes when I try to start screen sharing. It seems like there’s a problem with the foreground service permissions for media projection. I tried setting targetSdkVersion to 28 as a quick fix, but that doesn’t work because Google Play rejects apps targeting below 31.
Here’s a snippet of the error I’m getting:
java.lang.SecurityException: Starting FGS with type mediaProjection
callerApp=ProcessRecord{ee6725f 12034:com.example.myapp/u0a386} targetSDK=34 requires
permissions: all of the permissions allOf=true
[android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION] any of the permissions allOf=false
[android.permission.CAPTURE_VIDEO_OUTPUT, android:project_media]
It seems Android 14 requires new permissions for media projection, specifically FOREGROUND_SERVICE_MEDIA_PROJECTION along with either CAPTURE_VIDEO_OUTPUT or android:project_media. Has anyone else experienced this issue? Any workarounds that don’t compromise Play Store rules would be really helpful. Thanks!
yo, i hit this issue too. it’s a pain. try adding the FOREGROUND_SERVICE_MEDIA_PROJECTION permission to ur manifest. also, make sure ur requesting it at runtime before starting screenshare. if that don’t work, maybe look into other ways to do screensharing without foreground service for android 14. good luck!
Dealing with Android 14’s new permission requirements can be frustrating. I’ve been there. One thing that worked for me was implementing a version-specific approach. For Android 14 and above, I added the FOREGROUND_SERVICE_MEDIA_PROJECTION permission and ensured it was requested at runtime.
For older versions, I kept the existing implementation. This way, my app remained compatible across different Android versions without violating Play Store policies. I also found that updating dependencies, especially flutter_webrtc, to their latest versions often includes fixes for these new OS requirements.
If you’re still stuck, consider reaching out to the flutter_webrtc maintainers. They might have insights or be working on a more comprehensive solution. In the meantime, thoroughly testing on various Android versions can help identify any version-specific issues.
I’ve encountered a similar issue with Android 14 and screen sharing. The new permission requirements are indeed causing problems for many developers. From my experience, the most reliable solution is to update your app’s manifest file to include the new FOREGROUND_SERVICE_MEDIA_PROJECTION permission.
Add this line to your AndroidManifest.xml:
Also, make sure you’re requesting this permission at runtime before initiating screen sharing. You might need to update the flutter_webrtc package to the latest version that supports these new Android 14 requirements.
If you’re still facing issues after these changes, consider implementing a fallback mechanism for Android 14 devices that uses a different method for screen sharing, perhaps one that doesn’t require a foreground service. This approach has worked for some of my projects.