I am using
window.addEventListener('devicemotion', event => this.watchDeviceMotion(event))
watchDeviceMotion(event: any) {
let motionData = {
x: event.acceleration.x,
y: event.acceleration.y,
z: event.acceleration.z,
}
let rotationData = {
alpha: event.rotationRate.alpha,
beta: event.rotationRate.beta,
gamma: event.rotationRate.gamma
}
if (this.getSensorData) {
// console.log(JSON.stringify(motionData))
// console.log(JSON.stringify(rotationData))
this.userData.motionData.push(motionData)
this.userData.rotationData.push(rotationData)
}
}
to access accelerometer data on an Android device using Ionic with Angular. When inside the app, the event works at a frequency of 60 Hz but when the app is switched to background, the frequency drops around 9-10 Hz for the first 5 mins and at some point while still in background it goes back at 60 Hz and remains like that indefinitely.
I am also using the background plugin with
this.backgroundMode.enable();
this.backgroundMode.on('activate').subscribe(() => {
this.backgroundMode.disableWebViewOptimizations();
});
I tried to add disableBatteryOptimizations() to the background plugin with the corresponding condition in config.xml but still no luck.
I also tried the plugins for Device Motion and Gyroscope but they behave the same.
How should I prevent the frequency from slowing down? Has anyone else encountered this problem before?