Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingPluginException(No implementation found for method[BUG] (Application killed time) #136

Closed
dimple3695 opened this issue Jul 5, 2020 · 10 comments
Labels

Comments

@dimple3695
Copy link

I used method channel and event channel for data get from native side(Android/Ios) . I am using background service for getting continues data. When my app terminate that's time showing error.

Unhandled Exception: MissingPluginException(No implementation found for method scanStartDevic
e on channel 'exampl/channelname/bluttoth')

App working perfectly when is open.

Please can you find solution?

@christocracy
Copy link
Member

You must not ignore the issue template. It’s not optional. Edit your issue to provide the information:

Your Environment

  • Plugin version:
  • Platform: iOS or Android
  • OS version:
  • Device manufacturer / model:
  • Flutter info (flutter info, flutter doctor):
  • Plugin config

To Reproduce
Steps to reproduce the behavior:
1.
2.
3.
4.

Debug logs

  • ios XCode logs,
  • Android: $ adb logcat

Additional context
Add any other context about the problem here.

@dimple3695
Copy link
Author

Plugin version: 0.3.2
Platform: Android
OS version: 10
Device manufacturer / model: Moto g6
Flutter Info: Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.17.2, on Microsoft Windows [Version 10.0.18362.900], locale en-IN)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.46.1)
[√] Connected device (1 available)

• No issues found!

To Reproduce
Steps to reproduce the behavior:

  1. I am using method channel for BLE device scan. I need continues fetch the data from native platform (Android/Ios)
    So I am using background fetch plugin. It's working when application is resume/pause,
    but when I terminate the application it's giving me exception in method channel.
  2. Here is my code

/////////////////////////////////////////////////////////////////
final FlutterView view = getFlutterView();

    methodChannel = new MethodChannel(view, "com.waterio/blutoothsdkmethodChannel");
    methodChannel.setMethodCallHandler(
            new MethodChannel.MethodCallHandler() {
                @Override
                public void onMethodCall(MethodCall call, MethodChannel.Result result) {
                    switch (call.method) {
                        case "scanDevice":
                            startScanning();
                            break;
                      case "scanStartDevice":
                            boolean startScan = startScanning();
                            if (startScan != false) {
                                result.success(updateScanStatusTextmsg);
                            } else {
                                result.success(startScan);
                            }
                            break;
                     default:
                            result.notImplemented();
                    }
                }
            }
    );

//////////////////////////////////////////////////////////////////
void backgroundFetchHeadlessTask() async {
print('[BackgroundFetch] Headless event received.');
print("Hey Milton.. Background headless fetch is successful");

//_getWaterHistoryRecordSync();
await _GetStartScanning();

BackgroundFetch.finish();
}
Future _GetStartScanning() async {
MethodChannel blutooth_channel = MethodChannel('com.waterio/blutoothsdkmethodChannel');
try {
final dynamic result = await blutooth_channel.invokeMethod('scanStartDevice');
print('result... $result');
} on PlatformException catch (e) {
print('result ${e.message}');

}

}
Debug logs

Android: $ adb logcat

07-05 22:10:03.037 1942 1942 D TSBackgroundFetch: - finish
07-05 22:10:03.037 1942 1942 D TSBackgroundFetch: HeadlessJobService jobFinished
07-05 22:10:03.058 1942 1996 E flutter : [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method scanStartDevic
e on channel com.waterio/blutoothsdkmethodChannel)
07-05 22:10:03.058 1942 1996 E flutter : #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
07-05 22:10:03.058 1942 1996 E flutter :
07-05 22:10:03.058 1942 1996 E flutter : #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
07-05 22:10:03.058 1942 1996 E flutter : #2 _GetStartScanning (package:demo_app/main.dart:465:52)
07-05 22:10:03.058 1942 1996 E flutter : #3 getWaterDetails. (package:demo_app/main.dart:454:7)
07-05 22:10:03.058 1942 1996 E flutter : #4 _rootRunUnary (dart:async/zone.dart:1192:38)
07-05 22:10:03.058 1942 1996 E flutter : #5 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
07-05 22:10:03.058 1942 1996 E flutter : #6 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
07-05 22:10:03.058 1942 1996 E flutter : #7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
07-05 22:10:03.058 1942 1996 E flutter : #8 Future._propagateToListeners (dart:async/future_impl.dart:711:32)
07-05 22:10:03.058 1942 1996 E flutter : #9 Future._completeWithValue (dart:async/future_impl.dart:526:5)
07-05 22:10:03.058 1942 1996 E flutter : #10 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
07-05 22:10:03.058 1942 1996 E flutter : #11 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298:13)
07-05 22:10:03.058 1942 1996 E flutter : #12 SharedPreferencesHelper.getUserWaterBottleDetailsState (package:demo_app/resources/shared_pref_service.dart)
07-05 22:10:03.058 1942 1996 E flutter :
07-05 22:10:03.058 1942 1996 E flutter : #13 getWaterDetails (package:demo_app/main.dart:444:33)
07-05 22:10:03.058 1942 1996 E flutter : #14 backgroundFetchHeadlessTask (package:demo_app/main.dart:340:9)
07-05 22:10:03.058 1942 1996 E flutter : #15 _headlessCallbackDispatcher. (package:background_fetch/background_fetch.dart:427:15)
07-05 22:10:03.058 1942 1996 E flutter : #16 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:409:55)
07-05 22:10:03.058 1942 1996 E flutter : #17 MethodChannel.setMethodCallHandler. (package:flutter/src/services/platform_channel.dart:377:54)
07-05 22:10:03.058 1942 1996 E flutter : #18 _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binding.dart:199:33)
07-05 22:10:03.058 1942 1996 E flutter : #19 _invoke3. (dart:ui/hooks.dart:290:15)
07-05 22:10:03.058 1942 1996 E flutter : #20 _rootRun (dart:async/zone.dart:1184:13)
07-05 22:10:03.058 1942 1996 E flutter : #21 _CustomZone.run (dart:async/zone.dart:1077:19)
07-05 22:10:03.058 1942 1996 E flutter : #22 _CustomZone.runGuarded (dart:async/zone.dart:979:7)
07-05 22:10:03.058 1942 1996 E flutter : #23 _invoke3 (dart:ui/hooks.dart:289:10)
07-05 22:10:03.058 1942 1996 E flutter : #24 _dispatchPlatformMessage (dart:ui/hooks.dart:164:5)

@christocracy
Copy link
Member

christocracy commented Jul 5, 2020

Your issue is with this:

MissingPluginException(No implementation found for method scanStartDevic
e on channel com.waterio/blutoothsdkmethodChannel)

This is not related to background_fetch.

@stale
Copy link

stale bot commented Mar 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

@stale stale bot added the stale label Mar 19, 2021
@stale
Copy link

stale bot commented Jun 16, 2021

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

@stale stale bot closed this as completed Jun 16, 2021
@bilal-codingkey
Copy link

@christocracy I seems to be facing same predicament. I want to invoke a method on native side(android) through method channel within the headless callback. It seems to work fine until app isn't terminated but as it is terminated MissingPluginException(No implementation found for method) exception is thrown.

It seems like we need to register our method channel with your plugin, so that it's discoverable when app is started in headless fashion.

@christocracy
Copy link
Member

want to invoke a method on native side(android) through method channel within the headless callback

The /example app does that with the shared_preferences plugin:

prefs.setString(EVENTS_KEY, jsonEncode(events));

@bilal-codingkey
Copy link

bilal-codingkey commented Jun 5, 2024

want to invoke a method on native side(android) through method channel within the headless callback

The /example app does that with the shared_preferences plugin:

prefs.setString(EVENTS_KEY, jsonEncode(events));

I understand that. I am using shared_preferences plugin in callback as well, but I want to invoke a method(it isn't part of a separate plugin) on android side through methodChannel. Trying to do that throws MissingPluginException.

Here is a demo app to demonstrate the issue: https://github.com/bilal-codingkey/flutter_background_fetch_demo

@christocracy
Copy link
Member

You've implemented your custom MethodChannel in the Android MainActivity.

The MainActivity does not exist when an Android app is terminated. The MainActivity is the "head" of an Android app. Another name for "Headless" is "Activity-less".

Your only hope is to implement your custom MethodChannel in a custom Application.kt extension.

@bilal-codingkey
Copy link

bilal-codingkey commented Jun 7, 2024

@christocracy Thanks for explaining the reason and providing the suggestion.

For anyone who come across this later. You can move your native code of MainActivity to a separate Plugin and use that Plugin in the headless callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants