zhlicen
zhlicen

Reputation: 346

How to detect android watch is worn or not on AW2.0

Android wear 2.0 screen can be automatically locked right after it is taken off and the heart rate app / watch face would not work when it is not worn.

I am wondering is there any way to get current wear worn state without starting a service to listen to wear activity?

I tried to get the heart rate sensor accuracy, but I don't think it is a good way because I can not always get the right result in this way immediately.

Is there any system or gms API to get a current worn state synchronously?

Upvotes: 3

Views: 1382

Answers (1)

z153
z153

Reputation: 156

On watches with an off-body sensor (which lock immediately when not worn), you can check for the existence of the wakeup sensor TYPE_LOW_LATENCY_OFF_BODY_DETECT. This is only a public API in O+, but you can just use the actual value for N MR1 and below.

SensorManager sensorManager = 
    (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
boolean hasSensor = sensorManger.getDefaultSensor(34, true /* wakeup */) != null;

On watches without an off-body sensor (which don't lock immediately), your best bet is probably some sort of activity recognition, though there don't seem to be any public off-body activities that can be detected by Google APIs (see here).

Upvotes: 4

Related Questions