I use native code in my flutter app by EventChannel like the following code.
class MainActivity : FlutterActivity() {
private val ACTION_BROADCAST_RECEIVER = "com.datalogic.decodewedge.decode_action"
private val CATEGORY_BROADCAST_RECEIVER = "com.datalogic.decodewedge.decode_category"
private val EXTRA_DATA_STRING = "com.datalogic.decode.intentwedge.barcode_string"
private val EVENT_CHANNEL_BARCODE_INTENT = "app.channel.event.barcode_intent"
private var receiver: BroadcastReceiver? = null
private var filter: IntentFilter? = null
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine)
EventChannel(
flutterEngine.dartExecutor.binaryMessenger,
EVENT_CHANNEL_BARCODE_INTENT
).setStreamHandler(
object : EventChannel.StreamHandler {
override fun onListen(args: Any?, events: EventSink?) {
receiver = barcodeIntentReceiver(events)
filter = IntentFilter()
filter!!.addAction(ACTION_BROADCAST_RECEIVER)
filter!!.addCategory(CATEGORY_BROADCAST_RECEIVER)
registerReceiver(receiver, filter)
}
override fun onCancel(args: Any) {
Log.i("", "EVENT_CHANNEL_BARCODE_INTENT has been canceled")
}
}
)
}
private fun barcodeIntentReceiver(events: EventSink?): BroadcastReceiver? {
return object : BroadcastReceiver() {
override fun onReceive(p0: Context?, wedgeIntent: Intent?) {
val action = wedgeIntent!!.action
if (action == ACTION_BROADCAST_RECEIVER) {
val barcode_text = wedgeIntent.getStringExtra(EXTRA_DATA_STRING)
events?.success(barcode_text)
}
}
}
}
}
When I run the app, an error occurs like the following:
======== Exception caught by services library ======================================================
The following MissingPluginException was thrown while activating platform stream on channel app.channel.event.barcode_intent:
MissingPluginException(No implementation found for method listen on channel app.channel.event.barcode_intent)
When the exception was thrown, this was the stack:
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:313:7)
<asynchronous suspension>
#1 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:662:9)
<asynchronous suspension>
====================================================================================================
This way didn't work.
How do I resolve it?
I use native code in my flutter app by EventChannel like the following code.
When I run the app, an error occurs like the following:
This way didn't work.
How do I resolve it?