How to use Sensor API without ControlExtension?

隐身守侯 提交于 2019-12-11 08:05:08

问题


I am trying to make an app for the Smartwatch 2 that listens to the watch's accelerometer sensor and sends the values to another app running on the phone. Basically, its always listening to the accelerometer, whether the user is using the watch or not. As such, I'd like to do this using only the ExtensionService, and possibly the Notification API in the future to send the watch alerts based on the accelerometer.

The problem is, I can't figure out how to properly add and listen to the Sensors without a ControlExtension (as in the SampleSensorExtension).

The problems seems to be that there is no way to add sensors to the AccessorySensorManager outside of the ControlExtension. If I try to do this in the onCreate(), onStartCommand() or even the onRegisterResult() methods, I can't find any available sensors. As such, DeviceInfoHelper.isSensorSupported(this, this.getPackageName(), SensorTypeValue.)) always returns false.

How to get and add all supported sensors within the ExtensionService? Can a Sony Engineer please shed some light on the situation and consider a potential solution? Thanks!


回答1:


It is not possible to use the Sensor API without using the Control API as well. If you are using a Control extension it is possible to capture accelerometer data when the watch goes into low power mode as you know already.




回答2:


According to the documentation, it seems impossible (especially if the sensor activity is managed by the firmware of the SmartWatch and not the Android side).

It is stated that:

The accelerometer is available to the control extension that is currently started. If the control is paused, for example due to that the screen timeout is reached, the power button is pressed or another control extension is started, the sensor will also be stopped.

What you could do is using the Android device sensor(s) if it suits your requirements.



来源:https://stackoverflow.com/questions/22369495/how-to-use-sensor-api-without-controlextension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!