Isvisoft / flutter_screen_recording

A new Flutter plugin for record the screen.
MIT License
146 stars 142 forks source link

[Crash] App crashes on Android 10 #33

Closed mikron123 closed 4 years ago

mikron123 commented 4 years ago

Need to be a MediaProjection service for Android 10.

Plugin needs to be upgraded to support Android 10.

Thanks

salime45 commented 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?

mikron123 commented 4 years ago

wasn't on emulator. only on real devices.. happened on a XiaoMi 8 and Google Pixel. The reason was not initiating a 'ForegroundService'

salime45 commented 4 years ago

you mean it is not crashing in an emulator? We dont have this devices, Can you make the changes in the code?

mikron123 commented 4 years ago

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;

salime45 commented 4 years ago

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

mikron123 commented 4 years ago

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.

mikron123 commented 4 years ago

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.

salime45 commented 4 years ago

Merge in develop branch

FiveFingerDeathPunch commented 4 years ago

when mDisplayWidth and mDisplayHeight can be divisible by 10.it s work

kenle commented 4 years ago

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

salime45 commented 4 years ago

I removed the code from the example and put inside the plugin. Should work now in any android device.

Is in branch develop