Accessing sensor data of your Android devices just became quick and easy โก๏ธ
This library provides a convenience wrapper over the Sensor APIs for Android to be used with Jetpack Compose.
This library is a work-in-progress and is subject to major changes. Our team is working hard to get it stable as soon as possible. Thank you for your patience ๐บ
dependencies {
...
implementation("com.mutualmobile:composesensors:x.y.z")
}
dependencies {
...
implementation 'com.mutualmobile:composesensors:x.y.z'
}
Add https://oss.sonatype.org/content/repositories/snapshots
as a maven repository resource to be able to access SNAPSHOT versions of this library. Check tags
for the latest library version.
dependencyResolutionManagement {
...
repositories {
...
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
}
dependencyResolutionManagement {
...
repositories {
...
maven {
url = 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
}
The library provides straightforward state methods for multiple sensors like Accelerometer, Gyroscope, etc (more mentioned below). Following is an example on how to get the current values from the Accelerometer
:
val accelerometerState = rememberAccelerometerSensorState()
Use it in an example:
val accelerometerState = rememberAccelerometerSensorState()
// Optional: You could also write: rememberAccelerometerSensorState(sensorDelay = SensorDelay.Fastest) for fetching sensor data faster
Text(
text = "Force X: ${accelerometerState.xForce}" +
"\nForce Y: ${accelerometerState.yForce}" +
"\nForce Z: ${accelerometerState.zForce}" +
"\nIs Available?: ${accelerometerState.isAvailable}"
)
ComposeSensors plans to support the following Android sensors:
Sensor | Status | Composable |
---|---|---|
Accelerometer | โ | rememberAccelerometerSensorState() |
Magnetic Field | โ | rememberMagneticFieldSensorState() |
Gyroscope | โ | rememberGyroscopeSensorState() |
Light | โ ๏ธ | rememberLightSensorState() |
Pressure | โ ๏ธ | rememberPressureSensorState() |
Proximity | โ ๏ธ๏ธ | rememberProximitySensorState() |
Gravity | โ ๏ธ | rememberGravitySensorState() |
Linear Acceleration | โ ๏ธ | rememberLinearAccelerationSensorState() |
Rotation Vector | โ ๏ธ๏ธ | rememberRotationVectorSensorState() |
Relative Humidity | WIP | |
Ambient Temperature | โ ๏ธ | rememberAmbientTemperatureSensorState() |
Magnetic Field (Uncalibrated) | โ ๏ธ๏ธ | rememberUncalibratedMagneticFieldSensorState() |
GameRotation Vector | โ ๏ธ | rememberGameRotationVectorSensorState() |
Gyroscope (Uncalibrated) | WIP | |
Significant Motion | โ | N/A |
Step Detector | โ ๏ธ | rememberStepDetectorSensorState() |
Step Counter | โ ๏ธ | rememberStepCounterSensorState() |
Geomagnetic Rotation Vector | โ ๏ธ๏ธ | rememberGeomagneticRotationVectorSensorState() |
Heart Rate | โ ๏ธ | rememberHeartRateSensorState() |
Pose6DOF | โ | N/A |
Stationary Detect | WIP | |
Motion Detect | WIP | |
Heart Beat | โ | N/A |
Low Latency Off-Body Detect | โ | N/A |
Accelerometer (Uncalibrated) | WIP | |
Hinge Angle | โ ๏ธ | rememberHingeAngleSensorState() |
Head Tracker | โ | N/A |
Accelerometer Limited Axes | WIP | |
Gyroscope Limited Axes | โ ๏ธ๏ธ | rememberLimitedAxesGyroscopeSensorState() |
Accelerometer Limited Axes (Uncalibrated) | WIP | |
Gyroscope Limited Axes (Uncalibrated) | โ | N/A |
Heading | WIP | |
All | โ | N/A |
Copyright 2023 MutualMobile
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.