请问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
相关问题
如何保证振弦传感器的测量精度?
2335浏览 • 0回复 待解决
什么是智能振弦传感器的电子标签?
2182浏览 • 0回复 待解决
订阅接近光传感器只出一次数据
685浏览 • 1回复 待解决
请问HUAWEI DevEco Device Tool会开源吗?
5250浏览 • 1回复 已解决
如何设置屏幕方向为横屏
491浏览 • 1回复 待解决
如何屏蔽方向键走焦事件
964浏览 • 1回复 待解决