-
-
Notifications
You must be signed in to change notification settings - Fork 810
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 when using in isolate with Android Alarm Service #220
Comments
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. |
The plugin simply does not register itself when it has no Activity Context.
|
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. |
Prevent closing |
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. |
Prevent closing |
2:35:37.911 592 info flutter.tools [ +192 ms] E/flutter (23714): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method getLocation on channel lyokone/location) |
I am getting the same issue, even with geolocator plugin also, Same error when used with android alarm manager |
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. |
Prevent closing |
Hey ! Sorry for the huge delay in response, I was mostly away from my computer this last months. I'll look into that as soon as possible ! |
Hey, I've just updated the plugin to version 2.5.0, which supports embedding V2, according to this, it should be working fine without any more work. Please let me know if it fixed the issue :) |
Nice! Thanks a lot @Lyokone ! |
@sanchitd5 Have you upgraded your project to Android Embedding V2 ? https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects |
@Lyokone Yes, I have created a new project using "flutter create -i objc -a java" . it is still giving the same issue. |
Would you mind providing a project showing the error ? It would be easier for me to help you. |
@Lyokone I have invited you to the repo "https://github.com/sanchitd5/flutter_bluetoothScanner/tree/locationEmit-locationPackage" this branch is the one with the code in it "locationEmit-locationPackage". Also, this is the path for the exact file where the code is lib/utils/AndroidAlarmBootstrapper/AlarmManagerBootstraper.dart |
I've tested with a small project and it seems that the Android activity isn't set when the plugin is running in isolate. I have a couple of idea that I'll try to resolve this :) |
Hi @Lyokone |
Hey ! Not sure what causing this and how to force the plugin to get an Activity :/ Were you able to get a location fix with geolocator ? |
Geolocator is working without Activity, but it has another issue now =( |
any updates on this ? I get the same error using the plugin foreground_service to run in background |
The same behaviour is observed when used with firebase messaging onBackground callback |
Any update on this? |
Hey guys. I have the same problem. what should I do to fix it ? |
additionally I tried to solve this problem by using Java native code. but didn't work. |
Hello, I am also having the same problem when I try to use location with the android_alarm_manager plugin. |
Hey guys. Note : since I need to get Location every 1 minute and minimum period of background_fetch is 15 minutes , I do this. in other words I start and stop background_fetch every 1 minute by android_alarm_manager. in main.dart : main.dartvoid getLocation() async{ Location location = Location(); LocationData locationData = await location.getLocation(); print(locationData.latitude); // do something else } void myAlarmManager()async { BackgroundFetch.scheduleTask(TaskConfig( taskId: 'getLocation', delay: 1000, enableHeadless: true, stopOnTerminate: false, forceAlarmManager: true, startOnBoot: true, )); } void backgroundFetchHeadlessTask(String taskId) async { print("[BackgroundFetch] Headless event received: $taskId"); getLocation(); BackgroundFetch.finish(taskId); BackgroundFetch.stop(); } void main() async{ final backgroundLocationID = 0; WidgetsFlutterBinding.ensureInitialized(); await AndroidAlarmManager.initialize(); runApp(InspectorApp()); BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask); await AndroidAlarmManager.periodic( const Duration(minutes: 1), backgroundLocationID, myAlarmManager, rescheduleOnReboot: true, ); } ....... class MyAppState extends State{ ...... @override void initState() { initPlatformState(); super.initState(); } void initPlatformState() async { // Configure BackgroundFetch. BackgroundFetch.configure(BackgroundFetchConfig( minimumFetchInterval: 15, forceAlarmManager: false, stopOnTerminate: false, startOnBoot: true, enableHeadless: true, requiresBatteryNotLow: false, requiresCharging: false, requiresStorageNotLow: false, requiresDeviceIdle: false, requiredNetworkType: NetworkType.ANY, ), _onBackgroundFetch).then((int status) { print('[BackgroundFetch] configure success: $status'); }).catchError((e) { print('[BackgroundFetch] configure ERROR: $e'); }); if (!mounted) return; } void _onBackgroundFetch(String taskId) async { print("[BackgroundFetch] Event received: $taskId"); getLocation(); BackgroundFetch.finish(taskId); BackgroundFetch.stop(); } } create a new class and named it MyApplication.java. MyApplication.javapackage yourPackageName; import io.flutter.app.FlutterApplication; import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback; import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin; import io.flutter.plugins.androidalarmmanager.AlarmService; import io.flutter.plugins.androidalarmmanager.AndroidAlarmManagerPlugin; import com.lyokone.location.LocationPlugin; import com.transistorsoft.flutter.backgroundfetch.BackgroundFetchPlugin; public class MyApplication extends FlutterApplication implements PluginRegistrantCallback { @Override public void onCreate() { super.onCreate(); AlarmService.setPluginRegistrant(this); } @Override public void registerWith(PluginRegistry registry) { AndroidAlarmManagerPlugin.registerWith(registry.registrarFor("io.flutter.plugins.androidalarmmanager.AndroidAlarmManagerPlugin")); SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")); LocationPlugin.registerWith(registry.registrarFor("com.lyokone.location.LocationPlugin")); BackgroundFetchPlugin.registerWith(registry.registrarFor("com.transistorsoft.flutter.backgroundfetch.BackgroundFetchPlugin")); } } and set name attribute in application tag to ".MyApplication" I hope to work for you |
@jafar96 this is very strange solution as background_fetch uses JobScheduler under the hood - the API similar to AlarmManager. So you are scheduling a background task the will schedule a background task... Also it will not work for Android older than 5.0 because background_fetch uses AlarmManager for old Android versions. |
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. |
@jafar96 its a good approach but its too much |
Describe the bug
I'm trying to get device location in a callback of android_alarm_service. So I create a new alarm:
Then
updateDeviceLocation
is called in a separateisolate
in this case. Here is the function:If I call
updateDeviceLocation
directly in main isolate all works fine. But whenupdateDeviceLocation
called by Alarm Manager in a separateisolate
I'm getting:I tried
flutter clean
, restarting and rebuilding everything, but no luck.Expected behavior
I hope this plugin can work fine in a separate
isolate
.Tested on:
Additional logs
The text was updated successfully, but these errors were encountered: