-
Notifications
You must be signed in to change notification settings - Fork 124
Class cast exception #7
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
Comments
EDIT. Forget about it, I didn't add service to AndroidManifest. But in the issue above, all code was done step by step with the documentation. This is getting weirder and weirder. I took your example and installed it on the device with Android 8.0, when I clicked the start button, the console shows me only: The same happened on Android 10 and 11. |
@zawadZwd |
Sure thing void geolocatorCallback() async {
try {
FlutterForegroundTask.initDispatcher((timestamp) async {
var localization = await Geolocator.getCurrentPosition();
dev.log('timestamp: ${timestamp.toString().substring(0, 19)}');
FlutterForegroundTask.update(
notificationTitle: 'Current GPS localization',
notificationText: '${localization.latitude}, ${localization.longitude}',
);
}, onDestroy: (timestamp) async {
dev.log('geolocatorCallback() is dead.. x_x');
});
} catch (e) {
dev.log('Geolocator callback error: $e');
}
} Even without localization variable the result is the same |
But from my observation looks like the issue occurs after invoking task trigger: Future<void> turnOnGps() async {
try {
var localization = await Geolocator.getCurrentPosition();
FlutterForegroundTask.start(
notificationTitle: 'Current GPS localization',
notificationText: '${localization.latitude}, ${localization.longitude}',
callback: geolocatorCallback,
);
} catch (e) {
print('Error: $e');
}
} |
@zawadZwd |
@zawadZwd The second issue is most likely a permission issue. Check this out.
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
void callback() {
final positionStream = Geolocator.getPositionStream();
StreamSubscription<Position>? streamSubscription;
FlutterForegroundTask.initDispatcher((timestamp) async {
if (streamSubscription != null) return;
streamSubscription = positionStream.listen((event) {
print('timestamp: ${timestamp.toString()}');
FlutterForegroundTask.update(
notificationTitle: 'Current GPS localization',
notificationText: '${event.latitude}, ${event.longitude}');
});
}, onDestroy: (timestamp) async {
await streamSubscription?.cancel();
print('callback() is dead.. x_x');
});
} |
@zawadZwd |
You rock! Things work perfectly fine now :) |
Uh oh!
There was an error while loading. Please reload this page.
Hello there,
tldr; when i'm trying to start foreground tast I get this exception:
My code is pretty much like in the example and I have no clue where to find the problem. In a task, I'm displaying the timestamp so I do not know what kind of integer is trying to be cast into long.
The text was updated successfully, but these errors were encountered: