扫描可用 wifi 时出现异常 - java.lang.IllegalStateException:回复已提交

While Scanning available wifi getting exception - java.lang.IllegalStateException: Reply already submitted

当我使用 wifi 请求网络中的可用 wifi 列表时,出现以下异常。

异常:

E/MethodChannel#plugins.ly.com/wifi(29023): Failed to handle method call
E/MethodChannel#plugins.ly.com/wifi(29023): java.lang.IllegalStateException: Reply already submitted
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:151)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.error(MethodChannel.java:230)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.finishWithError(WifiDelegate.java:341)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.finishWithAlreadyActiveError(WifiDelegate.java:337)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.getWifiList(WifiDelegate.java:172)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiPlugin.onMethodCall(WifiPlugin.java:58)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#plugins.ly.com/wifi(29023):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/flutter (29023): PlatformException(error, Reply already submitted, null)
E/MethodChannel#plugins.ly.com/wifi(29023): Failed to handle method call
E/MethodChannel#plugins.ly.com/wifi(29023): java.lang.IllegalStateException: Reply already submitted
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:151)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.error(MethodChannel.java:230)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.finishWithError(WifiDelegate.java:341)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.finishWithAlreadyActiveError(WifiDelegate.java:337)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.getWifiList(WifiDelegate.java:172)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiPlugin.onMethodCall(WifiPlugin.java:58)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#plugins.ly.com/wifi(29023):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/flutter (29023): PlatformException(error, Reply already submitted, null)
E/MethodChannel#plugins.ly.com/wifi(29023): Failed to handle method call
E/MethodChannel#plugins.ly.com/wifi(29023): java.lang.IllegalStateException: Reply already submitted
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:151)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.error(MethodChannel.java:230)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.finishWithError(WifiDelegate.java:341)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.finishWithAlreadyActiveError(WifiDelegate.java:337)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiDelegate.getWifiList(WifiDelegate.java:172)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.ly.wifi.WifiPlugin.onMethodCall(WifiPlugin.java:58)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:222)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:96)
E/MethodChannel#plugins.ly.com/wifi(29023):     at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:656)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.MessageQueue.next(MessageQueue.java:336)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.os.Looper.loop(Looper.java:174)
E/MethodChannel#plugins.ly.com/wifi(29023):     at android.app.ActivityThread.main(ActivityThread.java:7356)
E/MethodChannel#plugins.ly.com/wifi(29023):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/MethodChannel#plugins.ly.com/wifi(29023):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/flutter (29023): PlatformException(error, Reply already submitted, null)

代码:

Future<List<WifiResult>> getAvailableWifi() async {
List<WifiResult> filteredList = [];
bool match = true;

return Wifi.list('');
List<WifiResult> wifis =  await Wifi.list('');
return wifis;
}

WifiManager.startScan() 使用限制为每 2 分钟扫描 4 次。 - 所有后台应用合并限制为每 30 分钟扫描一次。"

请检查您是否在 2 分钟内呼叫 WifiManager.startScan() 超过四次。

参考link:https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-throttling