Closed mikron123 closed 4 years ago
I try in different devices and emulator with this version and works fine.
Can you tell me a emulator where this not works?
wasn't on emulator. only on real devices.. happened on a XiaoMi 8 and Google Pixel. The reason was not initiating a 'ForegroundService'
you mean it is not crashing in an emulator? We dont have this devices, Can you make the changes in the code?
Another reason that I found is that the calculated resolution wasn't right for the Mi 8.. windowManager.defaultDisplay.getRealSize(screenSize); should be used to get the screen size, and then use the ratio with val screenRatio : Double = (screenSize.x.toDouble() / screenSize.y.toDouble())
then we can use the ratio to calculate a give width. mDisplayWidth = 1280; mDisplayHeight = mDisplayWidth / screenRatio;
That code doesn't work on all devices. We disapprove of it for that. Each Android device treats the resolution at which it can record differently
I've tested it on all emulator + devices that crashed before and it works.. the problem is you relied on the resolution minus the status bar... which caused the crash.
I've committed some changed, you're welcome to test them.
There's an Android Camera API to get all available recording resolutions, but Camera is deprecated, Camera 2 is not. The realSize + Ratio calculation worked on all tested devices and prevented the crash in some.. so I don't see the problem.
Merge in develop branch
when mDisplayWidth and mDisplayHeight can be divisible by 10.it s work
I believe there is a new security feature in Android 10 that is a breaking change for screen recording unfortunately. Must run a foreground service type "mediaProjection".
Related issue: https://stackoverflow.com/questions/61276730/media-projections-require-a-foreground-service-of-type-serviceinfo-foreground-se
Check these plugins for examples of what may need to be implemented: https://pub.dev/packages/foreground_service https://pub.dev/packages/flutter_foreground_plugin
Additions needed in the Manifest when using foreground service for media projection:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<service android:name="---service package name---" android:foregroundServiceType="mediaProjection" />
Also a good reference: https://medium.com/@juliozynger/media-projection-and-audio-capture-1ca72e271e9c Related code that can help updating Android code in the plugin: https://github.com/julioz/AudioCaptureSample
I removed the code from the example and put inside the plugin. Should work now in any android device.
Is in branch develop
Need to be a MediaProjection service for Android 10.
Plugin needs to be upgraded to support Android 10.
Thanks