文档开发者中心
我的

请问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,把传感器类型改成设备方向传感器,但是没有回调,请问这个传感器要如何使用?希望有官方人员解答一下!

点赞
收藏
1
回复
5
分享
举报
浏览448 发布于2021-10-20 08:23未知归属地
全部评论
最多点赞
最新发布
最早发布
楼主你好,你可以参考官方codelab “基于HarmonyOS获取设备位置”中方向传感器的使用方法,参考链接:https://developer.huawei.com/consumer/cn/codelabsPortal/carddetails/HarmonyOS-Location
3楼回复于2021-10-22 02:37 未知归属地

可以去这个代码仓库看一下。zip下载下来就能用。主要是通过Category不同的参数类型调用不同的传感器。

https://gitee.com/cluo29/harmony7

传感器开发指导

https://developer.harmonyos.com/cn/docs/documentation/doc-guides/device-sensors-guidelines-0000001050199987

CategoryOrientationAgent

https://developer.harmonyos.com/cn/docs/documentation/doc-references/categoryorientationagent-0000001054238979

2
2楼回复于2021-10-20 11:07 未知归属地
  • ******7714@**.com
    你好,你发的仓库访问受限,请问可以发个可以访问的仓库吗?
    2021-10-21 01:20 未知归属地
  • 又要沉了回复******7714@**.com
    开了。再试试
    2021-10-24 09:00 未知归属地
欢迎开发小伙伴们进来帮帮楼主
1楼回复于2021-10-20 09:03 未知归属地
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。