Reputation: 520
for a job I need to call Custom MethodChannel and get information from Android native code, but I get the error "No implementation found for method "sendCustomData" on channel com.mobile.app/customChannel".
My code is below:
class myService implements UserDataCollector {
static final myService _singleton = myService._internal();
factory myService() {
return _singleton;
}
final _platform = const MethodChannel('com.mobile.app/customChannel');
myService._internal();
Future<void> sendCustomData(
{required String dataType, required Map<String, dynamic> data}) async {
if (RemoteConfigController.sendCustomDataToVeloxity) {
final encodedJson = jsonEncode(data);
_platform.invokeMethod("sendCustomData", {
"customData": encodedJson,
"customDataType": dataType,
});
}
}
}
Android :
class MainActivity : FlutterActivity() {
private val CHANNEL = "com.mobile.app/customChannel";
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
GeneratedPluginRegistrant.registerWith(flutterEngine)
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
if (call.method == "sendCustomData") {
result.success(true)
} else {
result.notImplemented()
}
}
}
}
Use
await veloxityService.sendCustomData(dataType: "send_data", data: {""});
note : Namings are examples.
Thanks.
Upvotes: 0
Views: 43
Reputation: 520
The problem was caused by incorrect android:name naming.
android:name="com.app.MainActivity"
Upvotes: 0