- Notifications
You must be signed in to change notification settings - Fork6
A thin wrapper around the Android Sensor APIs, designed to make it easier to work with them in Jetpack Compose.
License
ricknout/compose-sensors
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This library is a thin wrapper around theAndroid Sensor APIs,designed to make it easier to work with them inJetpack Compose.
![]() | ![]() | ![]() |
|---|
In modulebuild.gralde.kts file:
dependencies { implementation("dev.ricknout.composesensors:composesensors:$version")}The library is available viamavenCentral(). Versions can be found on thereleases page.
The core APIs provide composable access to the Android sensor framework classes:
// Get the SensorManagerval sensorManager= getSensorManager()// Check if a certain type of sensor is availableval available= isSensorAvailable(type=Sensor.TYPE_ACCELEROMETER)// Get a sensorval sensor= getSensor(type=Sensor.TYPE_ACCELEROMETER)// Remember a sensor value as State that updates as SensorEvents arriveval sensorValue by rememberSensorValueAsState(type=Sensor.TYPE_ACCELEROMETER) { event->// Transform SensorEvents}
The per-sensor APIs build on the core APIs and provide convenience by:
- Not having to pass the sensor
typeparameter - Handling the transformation of
SensorEvents for each type of sensor, by using theSensorValueclass
// Check if accelerometer sensor is availableval available= isAccelerometerSensorAvailable()// Get accelerometer sensorval sensor= getAccelerometerSensor()// Remember accelerometer sensor value as State that updates as SensorEvents arriveval sensorValue by rememberAccelerometerSensorValueAsState()// Accelerometer sensor values. Also available: sensorValue.timestamp, sensorValue.accuracyval (x, y, z)= sensorValue.value
The following sensor types are available:
| Type | Availability | Sensor | Sensor value |
|---|---|---|---|
| ⏩ Accelerometer | isAccelerometerSensorAvailable | getAccelerometerSensor | rememberAccelerometerSensorValueAsState |
| 🌡️ Ambient Temperature | isAmbientTemperatureSensorAvailable | getAmbientTemperatureSensor | rememberAmbientTemperatureSensorValueAsState |
| ⏬ Gravity | isGravitySensorAvailable | getGravitySensor | rememberGravitySensorValueAsState |
| 🔄 Gyroscope | isGyroscopeSensorAvailable | getGyroscopeSensor | rememberGyroscopeSensorValueAsState |
| 💡 Light | isLightSensorAvailable | getLightSensor | rememberLightSensorValueAsState |
| ⏪ Linear Acceleration | isLinearAccelerationSensorAvailable | getLinearAccelerationSensor | rememberLinearAccelerationSensorValueAsState |
| 🧲 Magnetic field | isMagneticFieldSensorAvailable | getMagneticFieldSensor | rememberMagneticFieldSensorValueAsState |
| 💨 Pressure | isPressureSensorAvailable | getPressureSensor | rememberPressureSensorValueAsState |
| 🔛 Proximity | isProximitySensorAvailable | getProximitySensor | rememberProximitySensorValueAsState |
| 💧 Relative Humidity | isRelativeHumiditySensorAvailable | getRelativeHumiditySensor | rememberRelativeHumiditySensorValueAsState |
Watch this space, more types to come!
Copyright 2023 Nick RoutLicensed to the Apache Software Foundation (ASF) under one or more contributorlicense agreements. See the NOTICE file distributed with this work foradditional information regarding copyright ownership. The ASF licenses thisfile to you under the Apache License, Version 2.0 (the "License"); you may notuse this file except in compliance with the License. You may obtain a copy ofthe License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS, WITHOUTWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See theLicense for the specific language governing permissions and limitations underthe License.About
A thin wrapper around the Android Sensor APIs, designed to make it easier to work with them in Jetpack Compose.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.


