endmr11 / ed_screen_recorder

Screen recorder plugin for Flutter. Supports IOS and Android devices.
MIT License
26 stars 36 forks source link

Can't start record in android 14 #100

Closed lescalona1976 closed 1 month ago

lescalona1976 commented 2 months ago

Hello everyone!

I'm stuck, the app crashes when trying to migrate to Andorid 14 API Level 34

I would greatly appreciate any support you can provide.

flutter doctor Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.19.1, on Microsoft Windows [Version 10.0.22631.4037], locale en-US) [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [√] Chrome - develop for the web [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.6) [√] Android Studio (version 2022.3) [√] Connected device (4 available) [√] Network resources

device: Galaxy A34 5G - version android: 14

Trying to catch error message, I get the following

D/AndroidRuntime(16694): Shutting down VM E/AndroidRuntime(16694): FATAL EXCEPTION: main E/AndroidRuntime(16694): Process: com.stelliscorp.eworkout, PID: 16694 E/AndroidRuntime(16694): java.lang.IllegalStateException: Reply already submitted E/AndroidRuntime(16694): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:431) E/AndroidRuntime(16694): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:272) E/AndroidRuntime(16694): at com.ed_screen_recorder.ed_screen_recorder.EdScreenRecorderPlugin.HBRecorderOnStart(EdScreenRecorderPlugin.java:268) E/AndroidRuntime(16694): at com.ed_screen_recorder.ed_screen_recorder.HBRecorder$1.onReceiveResult(HBRecorder.java:409) E/AndroidRuntime(16694): at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:50) E/AndroidRuntime(16694): at android.os.Handler.handleCallback(Handler.java:958) E/AndroidRuntime(16694): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(16694): at android.os.Looper.loopOnce(Looper.java:230) E/AndroidRuntime(16694): at android.os.Looper.loop(Looper.java:319) E/AndroidRuntime(16694): at android.app.ActivityThread.main(ActivityThread.java:8919) E/AndroidRuntime(16694): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(16694): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578) E/AndroidRuntime(16694): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103) V/MediaProjection(16694): Dispatch stop to 0 callbacks.

ajsain commented 2 months ago

Hello guy's i'm also facing the same issue in android 13 and 14 if any one resolve that please let me know

lescalona1976 commented 2 months ago

Hello everyone!

You can follow the instructions in the following post.

Works perfectly for Android 13 API Level 33.

Now for Andorid 14 API Level 34 I managed to solve it by adding the following in the file

=============== \packages\ed_screen_recorder\android\src\main\AndoridManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />

=============== Additionally, for the file \packages\ed_screen_recorder\ed_screen_recorder\ScreenRecordService.java

//Declare the following variable private MediaProjection.Callback mMediaProjectionCallback;

//Update function initMediaProjection private void initMediaProjection() { mMediaProjection = ((MediaProjectionManager) Objects.requireNonNull(getSystemService(Context.MEDIA_PROJECTION_SERVICE))).getMediaProjection(mResultCode, mResultData); // Initialize and register the callback mMediaProjectionCallback = new MediaProjection.Callback() { @Override public void onStop() { Log.d(TAG, "MediaProjection stopped."); resetAll(); } }; mMediaProjection.registerCallback(mMediaProjectionCallback, null); }

//And Update function resetAll() private void resetAll() { stopForeground(true); if (mVirtualDisplay != null) { mVirtualDisplay.release(); mVirtualDisplay = null; } if (mMediaRecorder != null) { mMediaRecorder.setOnErrorListener(null); mMediaRecorder.reset(); } if (mMediaProjection != null) { mMediaProjection.unregisterCallback(mMediaProjectionCallback); mMediaProjection.stop(); mMediaProjection = null; } }

================ Finally, update packages\ed_screen_recorder\android\build.gradle to compileSdkVersion 34

================ Important: I am not an expert in Java programming. The modification is carried out by following logic and reading the help that Goolge Andorid provides for developers.

If anyone from the community can validate that the written code is missing something to work better, I would greatly appreciate it.

Good Luck!

lescalona1976 commented 1 month ago

Sorry,

First Apply https://github.com/endmr11/ed_screen_recorder/issues/95

After, https://github.com/endmr11/ed_screen_recorder/issues/100#issuecomment-2334294237