Detect if the phone is in pocket or not

2019-03-14 01:32发布

问题:

This question is not exactly about code but rather implementation.

I am working on an app that requires to check if the phone is in pocket or not. I have a simple algorithm to detect user steps when walking. The problem is movement in hand can also be registered as a step, e.g. when user runs the app and zeros the step values from the time that he/she does this to the point that the phone is in pocket, the app registeres a few steps.

My idea is to check proximity sensor and see if the phone is in pocket.

What I do with accelerometer sensor is that I continuesly read the accelerometer values in a buffer, when the buffer gets full then I calculate the steps (while calculating, the buffer is still accepting new accelerometer readings).

Since I heard that proximity sensor is interrupt based and not poll-based (like acc sensor is). How can I coordinate these two together?

Is it safe to say if I check proximity before writing acc values into buffer, and check it again when calculation starts, if proximity was not in FAR mode, I can assume the phone was in the pocket?

Any suggestion is welcome!