0

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.

1
  • Looks very much like your code tries to invoke initMethod, such as _platform.invokeMethod("initMethod", ... ). Are you sure that sendCustomData is only method ever called in your code ? Commented Jul 17, 2024 at 14:26

1 Answer 1

0

The problem was caused by incorrect android:name naming.

android:name="com.app.MainActivity" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.