carp.sensing-flutter icon indicating copy to clipboard operation
carp.sensing-flutter copied to clipboard

Unhandled Exception: No implementation found for method startBackgroundService on channel plugins.shounakmulay.com/foreground_sms_channel

Open bardram opened this issue 2 months ago • 2 comments

We get this on probe initialization:

E/flutter (11673): [ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: MissingPluginException(No implementation found for method startBackgroundService on channel plugins.shounakmulay.com/foreground_sms_channel)
E/flutter (11673): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:365:7)
platform_channel.dart:365
E/flutter (11673): <asynchronous suspension>
E/flutter (11673): 

bardram avatar Nov 03 '25 21:11 bardram

This is probably because the listening is set up during initialization:

/// The [TextMessageProbe] listens to SMS messages and collects a
/// [TextMessage] every time a new SMS message is received.
///
/// Only works on Android.
class TextMessageProbe extends StreamProbe {
  @override
  Stream<Measurement> get stream => _textMessageProbeController.stream;

  @override
  bool onInitialize() {
    if (!Platform.isAndroid) {
      throw SensingException('TextMessageProbe only available on Android.');
    }

    Telephony.backgroundInstance.listenIncomingSms(
      onNewMessage: (SmsMessage message) {
        _textMessageProbeController.add(
          Measurement.fromData(TextMessage.fromSmsMessage(message)),
        );
      },
      onBackgroundMessage: backgroundMessageHandler,
    );
    return true;
  }
}

This should probably be done in the start() method.

bardram avatar Nov 03 '25 21:11 bardram

Several observations:

  • It seems to be a problem when running in debug mode in Flutter - when "running", there seems not to be a problem.
  • Try to delete the GeneratedPluginRegistrant file (Java or Kotlin).
  • Run flutter clean.
  • Clean graddle - from the android folder, run ./gradlew clean.

bardram avatar Nov 11 '25 09:11 bardram