import sensor from "@kit.SensorServiceKit"
import { BusinessError } from '@kit.BasicServicesKit';
try {
sensor.once(sensor.SensorId.ORIENTATION, (data: sensor.OrientationResponse) => {
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);
console.info('Succeeded in the device rotating at an angle around the Z axis: ' + data.alpha);
});
} catch (error) {
let e: BusinessError.BusinessError = error as BusinessError.BusinessError;
console.error(`Failed to invoke once. Code: ${e.code}, message: ${e.message}`);
}
以下为方向传感器的三个值xyz获取的代码demo实例: