import { sensor } from '@kit.SensorServiceKit';
import { BusinessError } from '@kit.BasicServicesKit';
try {
sensor.on(sensor.SensorId.ORIENTATION, (data: sensor.OrientationResponse) => {
console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha);
console.info('Succeeded in the device rotating at an angle around the X axis: ' + data.beta);
console.info('Succeeded in the device rotating at an angle around the Y axis: ' + data.gamma);
}, { interval: 100000000 });
setTimeout(() => {
sensor.off(sensor.SensorId.ORIENTATION);
}, 500);
} catch (error) {
let e: BusinessError = error as BusinessError;
console.error(`Failed to invoke on. Code: ${e.code}, message: ${e.message}`);
}
建议用sensor:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-sensor-V5\#orientation9