请问SENSOR_TYPE_DEVICE_ORIENTATION设备方向传感器如何使用?

categoryOrientationAgent = new CategoryOrientationAgent();
CategoryOrientation categoryOrientation = categoryOrientationAgent.getSingleSensor(
    CategoryOrientation.SENSOR_TYPE_DEVICE_ORIENTATION);
categoryOrientationDataCallback = new ICategoryOrientationDataCallback() {
    @Override
    public void onSensorDataModified(CategoryOrientationData categoryOrientationData) {
        degree = categoryOrientationData.getValues()[0];
        handler.sendEvent(0);
    }

    @Override
    public void onAccuracyDataModified(CategoryOrientation categoryOrientation, int i) {
        // Called when sensor accuracy data changes.
        // This method is called by the application layer to process the accuracy data of the sensors.
        HiLog.info(LABEL_LOG, "%{public}s", "onAccuracyDataModified");
    }

    @Override
    public void onCommandCompleted(CategoryOrientation categoryOrientation) {
        // Called when the sensor completes command execution.
        // This method is called by the application layer to process the command execution result of the sensor.
        HiLog.info(LABEL_LOG, "%{public}s", "onCommandCompleted");
    }
};
categoryOrientationAgent.setSensorDataCallback(categoryOrientationDataCallback, categoryOrientation,
    SAMPLING_INTERVAL_NANOSECONDS);

通过修改官方的compass demo,把传感器类型改成设备方向传感器,但是没有回调,请问这个传感器要如何使用?希望有官方人员解答一下!

鸿蒙
传感器
HarmonyOS
2021-11-24 09:09:03
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
ohohy

你可以参考官方codelab “基于HarmonyOS获取设备位置”中方向传感器的使用方法,参考链接:https://developer.huawei.com/consumer/cn/codelabsPortal/carddetails/HarmonyOS-Location

分享
微博
QQ
微信
回复
2021-11-24 11:57:56