应用退到后台时,禁止使用传感器资源。
import { UIAbility } from '@kit.AbilityKit';
import { sensor } from '@kit.SensorServiceKit';
export default class EntryAbility extends UIAbility {
onForeground(): void {
// In the foreground, listen to the required type of sensor based on the service requirements
sensor.on(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
});
}
onBackground(): void {
// The background cancels the listening
sensor.off(sensor.SensorId.ACCELEROMETER);
}
} import { UIAbility } from '@kit.AbilityKit';
import { sensor } from '@kit.SensorServiceKit';
export default class EntryAbility extends UIAbility {
onForeground(): void {
// In the foreground, listen to the required type of sensor based on the service requirements
sensor.on(sensor.SensorId.ACCELEROMETER, (data: sensor.AccelerometerResponse) => {
});
}
onBackground(): void {
}
}