请问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
相关问题
如何保证振弦传感器的测量精度?
1730浏览 • 0回复 待解决
什么是智能振弦传感器的电子标签?
1288浏览 • 0回复 待解决
请问HUAWEI DevEco Device Tool会开源吗?
4567浏览 • 1回复 已解决
如何屏蔽方向键走焦事件
244浏览 • 1回复 待解决
OpenHarmony camera sensor调试疑问
110浏览 • 0回复 待解决
DevEco Device无法使用Previewer预览
27445浏览 • 3回复 待解决
如何使用预览查看服务效果
401浏览 • 1回复 待解决
请问Hi3516设备开发如何获得p7b文件
6983浏览 • 2回复 待解决
onTouch事件是否可以判断滑动方向
149浏览 • 1回复 待解决