[pedometer 4.0.1] stepCountStream listened in a Foreground Service does not trigger onData when phone is locked and screen is closed. Triggers when lock screen is shown again.
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Parti dall’implementazione Android alla base di Pedometer.stepCountStream e confronta la distribuzione degli eventi del sensore quando il dispositivo è sbloccato con quella quando è bloccato e lo schermo è spento. Riproduci il problema su Huawei P9 Lite con Android 7.0, utilizzando il punto di ingresso onStart del foreground service e il listener dei passi; il lavoro è completato quando i dati dei passi vengono distribuiti mentre lo schermo rimane bloccato e nero.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Device / Emulator and OS
- Device: Huawei P9 Lite
- OS: Android 7.0
I'm developing a Flutter app using pedometer package to track steps of the user. I want to count steps when app is closed as well, so I used flutter_background_service package as well in order to use foreground service on Android.
Basically this is my setup Background Service initialization logic (which is basically configured to use onStart method mentioned below):
Future<void> initializeBackgroundService() async {
final service = FlutterBackgroundService();
await service.configure(
androidConfiguration: AndroidConfiguration(
// this will be executed when app is in foreground or background in separated isolate
onStart: onStart,
// auto start service
autoStart: true,
isForegroundMode: true,
notificationChannelId: 'my_foreground',
initialNotificationTitle: 'AWESOME SERVICE',
initialNotificationContent: 'Initializing',
foregroundServiceNotificationId: 888,
),
iosConfiguration: IosConfiguration(
// auto start service
autoStart: true,
// this will be executed when app is in foreground in separated isolate
onForeground: onStart,
// you have to enable background fetch capability on xcode project
onBackground: onIosBackground,
),
);
}
onStart method (method called when foreground service is started):
@pragma('vm:entry-point')
Future<void> onStart(ServiceInstance service) async {
DartPluginRegistrant.ensureInitialized();
if (service is AndroidServiceInstance) {
service.on('setAsForeground').listen((event) {
service.setAsForegroundService();
});
service.on('setAsBackground').listen((event) {
service.setAsBackgroundService();
});
}
service.on('stopService').listen((event) {
service.stopSelf();
});
await activatePedometer(service);
}
And the content of activatePedometer method:
Future<void> activatePedometer(ServiceInstance service) async {
Stream<StepCount> pedometerStream = Pedometer.stepCountStream;
var subscription = pedometerStream.listen((stepCount) async {
print("STEP DATA LISTENED!!!");
}
Timer.periodic(const Duration(seconds: 1), (timer) async {
print('TIMER: ${DateTime.now()}!!!');
});
}
listen callback of stepCountStream is called in the following scenarios:
- When app is open
- When app is minimized
- When app is closed
- When phone lock screen is shown
And as you can see in the code, "STEP DATA LISTENED!!!" is printed on debug console.
But when phone is locked and screen goes black, this callback is not triggered even when user takes steps. When user uses lock button to show lock screen, it is triggered again. I want to be able to read step data even when phone is sleeping (locked and screen is black).
I wanted to see if this is a foreground service issue, that's why I added the following:
Timer.periodic(const Duration(seconds: 1), (timer) async {
print('TIMER: ${DateTime.now()}!!!');
});
"TIMER: 2024-04-27 21:58:00.657213!!!" is printed every second even when phone is locked and screen goes black. So it's clearly not a foreground service issue.
Has anyone encountered a problem similar to this? Is there anything I can do to ensure listen callback is triggered even when phone is sleeping (locked and screen is black)?
- Lingua principale
- Dart
- Stelle
- 609
- Fork
- 731
- Merge medio
- 33m
- PR unite (30g)
- 1
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di carp-dk/flutter-plugins
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
carp-dk/flutter-plugins#1297 · 1 commento ·
-
activity_recognition bugfix
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
carp-dk/flutter-plugins#1291 ·
-
[movesense_plus 1.2.0] Better handling connection error to connected deviceForse di nuovo libera @bardram l’ha presa 253 giorni fa e non c’è nessuna pull request aperta. Apertabugfix improvement movesense_plus
carp-dk/flutter-plugins#1286 · 1 assegnatario ·
-
improvement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 20/100
carp-dk/flutter-plugins#1271 · 1 commento ·
-
pedometer: ^4.1.1Apertaimprovement pedometer
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
carp-dk/flutter-plugins#1262 ·
Tutte le issue di carp-dk/flutter-plugins
Issue simili
-
backlog:low bug localization
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
simonoppowa/OpenNutriTracker#1366 ·
I maintainer di solito rispondono entro 1 giorno
-
backlog documentation good first issue priority: medium
Difficoltà 2/5 Mezza giornata Idoneità per principianti 78/100
-
coverage 1.16.0: format_coverage fails on the `{}` that `dart test --coverage` writes for fully skipped suitesForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
fyi-ecosystem platform-ios team-ios
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
flutter/flutter#194348 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno