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 isServiceRunning on channel id.flutter/background_service/android/method) #500

Open
mehrab-heidary opened this issue Jan 17, 2025 · 0 comments

Comments

@mehrab-heidary
Copy link

Hello, I used this package, but I have a problem. When I run the program and click the service activation option, I encounter this error:
This error is displayed on devices running Android 11 and below.

E/flutter ( 5396): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method isServiceRunning on channel id.flutter/background_service/android/method)
E/flutter ( 5396): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
E/flutter ( 5396):
E/flutter ( 5396): #1 FlutterBackgroundServiceAndroid.isServiceRunning (package:flutter_background_service_android/flutter_background_service_android.dart:127:18)
E/flutter ( 5396):
E/flutter ( 5396): #2 _onStart. (package:client_traccar_army/Core/data/background_service/background_service.dart:39:13)
E/flutter ( 5396):

This error is displayed on Android 12 and above devices.
I/flutter ( 8305): flutter_background_service_android threw an error: Exception: This class should only be used in the main isolate (UI App). The app may not function as expected until you remove this plugin from pubspec.yaml
E/flutter ( 5396): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method isServiceRunning on channel id.flutter/background_service/android/method)
E/flutter ( 5396): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
E/flutter ( 5396):
E/flutter ( 5396): #1 FlutterBackgroundServiceAndroid.isServiceRunning (package:flutter_background_service_android/flutter_background_service_android.dart:127:18)
E/flutter ( 5396):
E/flutter ( 5396): #2 _onStart. (package:client_traccar_army/Core/data/background_service/background_service.dart:39:13)
E/flutter ( 5396):

I have not installed the flutter_background_service_android package, but this error is displayed.

My codes:
main.dart file

Future main() async {
WidgetsFlutterBinding.ensureInitialized();
HttpOverrides.global = MyHttpOverrides();
await initializeService();
runApp(MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) =>
HomeProviderController(HomeRepository(TraccarDatasource())),
),
ChangeNotifierProvider(
create: (context) =>
ReportProviderController(ReportRepository(TraccarDatasource())),
),
],
child: const MyApp(),
));
}

background_service.dart file

Future initializeService() async {
final service = FlutterBackgroundService();
service.configure(
iosConfiguration: IosConfiguration(),
androidConfiguration: AndroidConfiguration(
foregroundServiceTypes: [AndroidForegroundType.location],
onStart: _onStart,
isForegroundMode: true,
autoStart: false));
}

@pragma('vm:entry-point')
void _onStart(ServiceInstance service) async {
final serviceRunning = FlutterBackgroundService();
AbTraccarDatasource _abTraccarDatasource = TraccarDatasource();
List loadValueLoop = [];
loadValueLoop = await _abTraccarDatasource.loadData();
if (service is AndroidServiceInstance) {
service.setForegroundNotificationInfo(
title: "ردیاب", content: "ردیاب در حال اجرا می باشد");
}
service.on('stopService').listen(
(event) {
service.stopSelf();
debugPrint("service off");
},
);
service.on('start').listen(
(event) {},
);
try {
Timer.periodic(
Duration(seconds: int.parse(loadValueLoop[4])),
(timer1) async {
if (!(await serviceRunning.isRunning())) timer1.cancel();
debugPrint("lop start");
_abTraccarDatasource.startGetSendLocationVoid(
loadValueLoop[2], loadValueLoop[3], loadValueLoop[1]);
},
);
} catch (e) {
debugPrint(e.toString());
}
}

void startBackgroundService() {
FlutterBackgroundService service = FlutterBackgroundService();
service.startService();
}

void stopBackgroundService() {
FlutterBackgroundService().invoke('stopService');
}

I have been having this problem for a long time but I haven't found a solution.

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

No branches or pull requests

1 participant