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

java.lang.IllegalStateException: Reply already submitted #2

Closed
a-v-ebrahimi opened this issue Feb 5, 2022 · 8 comments
Closed

java.lang.IllegalStateException: Reply already submitted #2

a-v-ebrahimi opened this issue Feb 5, 2022 · 8 comments

Comments

@a-v-ebrahimi
Copy link

When I call OptimizeBattery.stopOptimizingBatteryUsage(), I receive this error, I've added android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS to manifest :


E/DartMessenger(12723): Uncaught exception in binary message listener
E/DartMessenger(12723): java.lang.IllegalStateException: Reply already submitted
E/DartMessenger(12723): 	at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:431)
E/DartMessenger(12723): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:282)
E/DartMessenger(12723): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/DartMessenger(12723): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/DartMessenger(12723): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$AIEPqY6mWzaNK15HekX9bftoAXs.run(Unknown Source:12)
E/DartMessenger(12723): 	at android.os.Handler.handleCallback(Handler.java:938)
E/DartMessenger(12723): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/DartMessenger(12723): 	at android.os.Looper.loopOnce(Looper.java:226)
E/DartMessenger(12723): 	at android.os.Looper.loop(Looper.java:313)
E/DartMessenger(12723): 	at android.app.ActivityThread.main(ActivityThread.java:8582)
E/DartMessenger(12723): 	at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger(12723): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:563)
E/DartMessenger(12723): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)

@Bhat015
Copy link
Owner

Bhat015 commented Feb 5, 2022

Can you please share how OptimizeBattery.stopOptimizingBatteryUsage() was called? That would be helpful.
Thanks

@a-v-ebrahimi
Copy link
Author

@Bhat015
Please check my code:

showCustomDialog(
context,
Column(
mainAxisSize: MainAxisSize.min,
children: [
HtmlWidget(
L(context).batteryIsOptimizedMayStopAudio,
textStyle: getTextStyle(),
),
],
),
dialogTitle: L(context).openBatteryOptimizationSettings,
firstActionTitle: L(context).goto,
onFirstPress: (cont) {
//OptimizeBattery.openBatteryOptimizationSettings();
OptimizeBattery.stopOptimizingBatteryUsage();
},
hideOnFirstPress: true,
secondActionTitle: L(context).cancelReturn,
onSecondPress: (cont) {
Navigator.pop(cont);
});

@panalgin
Copy link
Contributor

I've fixed the issue, can I send a pull request?

@Bhat015
Copy link
Owner

Bhat015 commented Mar 10, 2022

Sure

@Bhat015
Copy link
Owner

Bhat015 commented Mar 20, 2022

@a-v-ebrahimi Issue is fixed.
Thanks to @panalgin . Will push this out soon

@Bhat015 Bhat015 closed this as completed Mar 20, 2022
@a-v-ebrahimi
Copy link
Author

a-v-ebrahimi commented Mar 21, 2022

Thanks, it does now crash now,
but OptimizeBattery.stopOptimizingBatteryUsage() does nothing at all, does not display a dialog or anything else.

@Bhat015
Copy link
Owner

Bhat015 commented Mar 21, 2022

You need to add the below permission in android mainfest file to use stopOptimizingBatteryUsage()

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

Also, please check if the battery is already optimized before calling stopOptimizingBatteryUsage()

@Bhat015
Copy link
Owner

Bhat015 commented Mar 21, 2022

I would recommend you to use it like this

  if (Platform.isAndroid) {
      final isIgnoringBatteryOptimization =
          await OptimizeBattery.isIgnoringBatteryOptimizations();
      if (!isIgnoringBatteryOptimization)
        await OptimizeBattery.stopOptimizingBatteryUsage();
    }

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

3 participants