android - 在 android 屏幕关闭时识别传感器是否工作

标签 android api sensors

我想确定用于 Activity 识别的传感器在设备屏幕关闭时是否正常工作。

一旦设备屏幕关闭, Activity 识别就会停止。我搜索了一下,发现当屏幕关闭时传感器不工作以节省电池。

所以有一种方法可以通过 isWakeUpSensor() 来识别此类传感器,但是 isWakeUpSensor() 从 API 21 开始适用。

如何让它在 API 14 及更高版本上运行。在开始 Activity 识别之前识别传感器。 与应用程序“移动”相同

最佳答案

经过一些搜索,我找到了这个 documentation哪个州

Up to KitKat, whether a sensor was a wake-up or a non-wake-up sensor was dictated by the sensor type: most were non-wake-up sensors, with the exception of the proximity sensor and the significant motion detector.

另一方面,显着运动检测器页面说

Implement only the wake-up version of this sensor. getDefaultSensor(SENSOR_TYPE_SIGNIFICANT_MOTION) returns a non-wake-up sensor

这让我很困惑。然而,它是一个复合传感器,这意味着它的唤醒取决于底层的实际传感器(我想)。

对此的更多研究表明 Android 4.3 (API 18) 中添加了显着运动检测器,因此您只剩下用于 API 14 设备中可用唤醒传感器的接近传感器,它主要用于在打电话时打开和关闭屏幕。

在我看来,如果没有 wake lock,就无法完全按照您的想法去做。 .

关于android - 在 android 屏幕关闭时识别传感器是否工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32044601/

相关文章:

android - 如何为我的 Android 应用程序获取 Google Places API key

android - Android-无法连接到其余API-错误请求

compiler-errors - 使用EY-80陀螺仪/加速度计/气压计的示例代码时遇到问题

Python 测试传感器,然后再次运行它们直到按下按键

java - ActionBarCompat 无法从父类(super class)中找到方法

android - restart() 时如何为视频播放重新创建 surfaceview?

api - 如何通过 Coinbase Api v2 发送 ping 通知?

visual-studio - 如何使用 Visual Studio 2015 和 Windows 10 模拟传感器?

android - 当用户按下主页按钮时,不会调用 onSaveInstanceState()

php - Android - 单击按钮时检索每行数据(下一个/上一个)