【发布时间】:2020-07-17 17:33:34
【问题描述】:
可以在大多数设备上轻松检测到物理主页按钮按下:
...
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+ and Fold。官方认为它是压力传感器,而不是按钮。
如何读取这个传感器?
TYPE_PRESSURE sensor event 与气压计相关,it shows the ambient air pressure in hPa or mbar。
getPressure() method 返回"the size of the capacitive object rather than literal pressure"。
我不需要有关压力级别的信息,我只想知道是否按下了压敏虚拟主页按钮。
【问题讨论】:
标签: android android-sensors android-homebutton samsung-galaxy