How to use Sensor API without ControlExtension?

2019-08-10 11:55发布

问题:

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.