Open eniafou opened 2 years ago
Try wrapping the code inside loadCounterValueJob
in a try
catch
block. I suspect a error is thrown but uncaught which causes the task to be cancelled.
ok, I did that :
Future<bool> loadCounterValueJob() async {
try {
print(await Permission.activityRecognition.isGranted);
Stream<StepCount> stepCountStream = Pedometer.stepCountStream;
StepCount rawStep = await stepCountStream.first;
DateTime timeStamp = rawStep.timeStamp;
int rawValue = rawStep.steps;
print(timeStamp);
print(rawValue);
}catch (err) {
print((err.toString()));
throw Exception(err);
}
return true;
}
Now the error output is :
D/PathProviderPlugin(29386): Use TaskQueues.
I/flutter (29386): #####################################################################################################################################################################################################################
I/flutter (29386): I am in the callbackDispatcher
I/flutter (29386): true
D/SensorManager(29386): registerListener :: 191, Step Counter Non-wakeup, 0, 0, com.example.pedometer.SensorEventListenerFactoryKt$sensorEventListener$1@763ddad
V/NativeCrypto(29386): Read error: ssl=0xb400007894630748: I/O error during system call, Software caused connection abort
V/NativeCrypto(29386): Write error: ssl=0xb400007894630748: I/O error during system call, Broken pipe
V/NativeCrypto(29386): SSL shutdown failed: ssl=0xb400007894630748: I/O error during system call, Success
15
W/ManagedChannelImpl(29386): [{0}] Failed to resolve name. status={1}
I/WM-WorkerWrapper(29386): Work [ id=a33089e0-32b3-4ed6-880e-973853052fda, tags={ be.tramckrijte.workmanager.BackgroundWorker } ] was cancelled
I/WM-WorkerWrapper(29386): java.util.concurrent.CancellationException: Task was cancelled.
I/WM-WorkerWrapper(29386): at androidx.work.impl.utils.futures.AbstractFuture.cancellationExceptionWithCause(AbstractFuture.java:1184)
I/WM-WorkerWrapper(29386): at androidx.work.impl.utils.futures.AbstractFuture.getDoneValue(AbstractFuture.java:514)
I/WM-WorkerWrapper(29386): at androidx.work.impl.utils.futures.AbstractFuture.get(AbstractFuture.java:475)
I/WM-WorkerWrapper(29386): at androidx.work.impl.WorkerWrapper$2.run(WorkerWrapper.java:298)
I/WM-WorkerWrapper(29386): at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)
I/WM-WorkerWrapper(29386): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
I/WM-WorkerWrapper(29386): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
I/WM-WorkerWrapper(29386): at java.lang.Thread.run(Thread.java:923)
Interesting. Do you have permissions? Can you upload a small sample repo on Github so it becomes easy to debug?
This will never work. By definition, Android does not allow to get steps information while your app is in background. Link: https://developer.android.com/guide/topics/sensors/sensors_overview#only-gather-sensor-data-in-the-foreground
I solved using only in Android the pluguin: https://pub.dev/packages/flutter_foreground_task combined with pedometer.
This will never work. By definition, Android does not allow to get steps information while your app is in background. Link: https://developer.android.com/guide/topics/sensors/sensors_overview#only-gather-sensor-data-in-the-foreground
I solved using only in Android the pluguin: https://pub.dev/packages/flutter_foreground_task combined with pedometer.
if possible please share your code ,repo or anything
Describe the error the task work fine when the app is open but when the user switch or terminate the app the task is cancelled
my code :
Error output:
Output of
flutter doctor -v