0

I use the MethodChannel(platform = const MethodChannel('example_service'); ) to control the background service for notification. for the android , i use the startService and stopService to control the service, running is fine. on android i use the notification to router to flutter page, router is success, but show the error( MissingPluginException(No implementation found for method startExampleService on channel example_service)) when i start/stop the service. If I open the app again on the phone, I can successfully start/stop the service.

How to solve it, thank you!

error:
2022-11-05 10:40:12.161 10300-10854/com.example.test221101 E/flutter: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method startExampleService on channel example_service)
    #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:294:7)




android:

val intent = FlutterActivity.withNewEngine().initialRoute("/").build(this);
var pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
builder = NotificationCompat.Builder(this, channelId)
builder
.setSmallIcon(R.mipmap.ic_launcher)
   .setContentTitle("Example Service")
   .setAutoCancel(true)
    .setContentIntent(pendingIntent)
   .setContentText("Example Service running")
   .setCategory(Notification.CATEGORY_SERVICE)
startForeground(1, builder.build())


flutter: 
 static var platform = const MethodChannel('example_service');
 await platform.invokeMethod('startExampleService');


0 Answers0