We just created a basic sensor algorithm to detect the phone handling event by processing the gyroscope values in the background service. As a best practice, it's suggested that you don't not block the onSensorChanged()
method. In our onSensorChanged()
method callback, we are just doing very simple calculations that will be completed before the next callback arrives. If you have any doubt in about whether it's a simple calculation or a complex one, then the best way is to log the time before and after the calculation, and compare it with the time interval between the callbacks.
You're reading from Android Sensor Programming By Example
The rest of the page is locked
You have been reading a chapter from
Android Sensor Programming By ExamplePublished in: Apr 2016Publisher: PacktISBN-13: 9781785285509
© 2016 Packt Publishing Limited All Rights Reserved