Things I was able to do :
sensorManager = getSystemService(SENSOR_SERVICE) as SensorManager
val accelerometerSensor =
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
sensorManager.registerListener(
accSensor,
accelerometerSensor,
SensorManager.SENSOR_DELAY_NORMAL
)
serviceIntent = Intent(context, SensorService::class.java)
context.startForegroundService(serviceIntent)
But I was not able to:
What might be the way to receive the Motion start and Motion end notifications/callback from the system so that we can decide to start/end foreground services.
The more common way of getting data out of smart sensors is to use a bridging device known as a gateway in each room. A gateway receives data from the sensors and makes it usable. Data is transmitted from the sensors to the gateway wirelessly.
You can access sensors available on the device and acquire raw sensor data by using the Android sensor framework. The sensor framework provides several classes and interfaces that help you perform a wide variety of sensor-related tasks.
Sensors can be hardware- or software-based. Hardware-based sensors are physical components built into a handset or tablet device. Hardware sensors derive their data by directly measuring specific environmental properties, such as acceleration, geomagnetic field strength, or angular change.
Smartphone sensor data provides organizations with a chance to learn about their employees' work patterns and behavior. IT could apply this data to the user authorization process to more accurately identify the users logging in to the device.
Too big for a comment, so I'll post it as an answer. And it is in some way an answer, but without proofs, just my experience.
I'm in no way an expert in the Android. But I know a thing or two about sensors in general. And the main thing is that they are always active (if not turned off entirely), and that there is always some noise. So
moving starts
/moving stops
.So, think of aggregation strategy and thresholds, don't show notifications if thresholds are not passed, and make your code fast (so that it won't use too much energy). And your are done... more or less... because these decisions are not easy to make. A lot of apps from big companies fail to make them right in all the cases. Just install a couple of pedometer-apps and you'll see that they all will show different counts of steps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With