如何读取压力传感器? [英] How to read the pressure sensor?

查看:542
本文介绍了如何读取压力传感器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数设备上可以轻松检测到按下物理主页按钮的情况:

Physical home button press can be detected easily on most of the devices:

...

public class ExampleAccessibilityService extends AccessibilityService {

    ...

    @Override
    protected boolean onKeyEvent(KeyEvent event) {    
        if (event.getKeyCode() == KEYCODE_HOME && event.getAction() == ACTION_DOWN)
            Log.d("Example", "The home key is pressed.");
        return super.onKeyEvent(event);
    }
}

但是,上面的代码在某些具有压敏虚拟主页按钮的设备上不起作用.我想这些三星Galaxy设备会受到影响: S8 S8 + ,S9,S9 +, Note10,Note10 +和Fold .正式地,它被认为是压力传感器,而不是按钮.

But the code above doesn't work on some devices that have a pressure-sensitive virtual home button. I suppose these Samsung Galaxy devices are affected: S8, S8+, S9, S9+, Note10, Note10+ and Fold. Officially, it is considered a pressure sensor, not a button.

如何读取此传感器?

TYPE_PRESSURE传感器事件与晴雨表它以hPa或mbar为单位显示环境气压.

getPressure()方法返回电容对象的大小而不是文字压力" .

我不需要有关压力水平的信息,我只想知道是否按下了压力感应虚拟主页按钮.

I don't need info about the level of pressure, I just want to know if the pressure-sensitive virtual home button is pressed.

推荐答案

此虚拟按钮不可用于应用程序,只能由该Samsung ROM访问.可以定义触发它所需的压力.无论如何阅读有什么意义?您的设备没有任何压力传感器,也称为气压计.您的意思是触摸屏,它对压力敏感,因此唯一的阅读机会可能是触摸屏驱动程序.

This virtual button is not for application usage and can only be accessed by that Samsung ROM. One can define the pressure required to trigger it. What's the point in reading it anyway? Your device does not have any pressure sensor, aka barometer. What you mean is the touchscreen, which is pressure sensitive - and so the only chance to read it might be the touchscreen driver.

这些是其供应商二进制文件的来源,用于AOSP .除非构建自定义ROM,否则可能无法将自定义功能绑定到触摸屏或将值公开给SDK.除了模拟硬件按钮事件之外,这些资源还应显示虚拟按钮的实际作用.

These are the sources for their vendor binaries, for AOSP. Unless building a custom ROM, there probably is no way to bind custom functionality to the touchscreen or to expose the value to the SDK. These sources should also show, what the virtual button actually does, beside emulating a hardware button event.

这篇关于如何读取压力传感器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆