Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A thin wrapper around the Android Sensor APIs, designed to make it easier to work with them in Jetpack Compose.

License

NotificationsYou must be signed in to change notification settings

ricknout/compose-sensors

Repository files navigation

This library is a thin wrapper around theAndroid Sensor APIs,designed to make it easier to work with them inJetpack Compose.

AccelerometerLightProximity

Usage

Dependency

In modulebuild.gralde.kts file:

dependencies {    implementation("dev.ricknout.composesensors:composesensors:$version")}

The library is available viamavenCentral(). Versions can be found on thereleases page.

Core APIs

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}

Per-sensor APIs

The per-sensor APIs build on the core APIs and provide convenience by:

  • Not having to pass the sensortype parameter
  • Handling the transformation ofSensorEvents for each type of sensor, by using theSensorValue class
// 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:

TypeAvailabilitySensorSensor value
⏩ AccelerometerisAccelerometerSensorAvailablegetAccelerometerSensorrememberAccelerometerSensorValueAsState
🌡️ Ambient TemperatureisAmbientTemperatureSensorAvailablegetAmbientTemperatureSensorrememberAmbientTemperatureSensorValueAsState
⏬ GravityisGravitySensorAvailablegetGravitySensorrememberGravitySensorValueAsState
🔄 GyroscopeisGyroscopeSensorAvailablegetGyroscopeSensorrememberGyroscopeSensorValueAsState
💡 LightisLightSensorAvailablegetLightSensorrememberLightSensorValueAsState
⏪ Linear AccelerationisLinearAccelerationSensorAvailablegetLinearAccelerationSensorrememberLinearAccelerationSensorValueAsState
🧲 Magnetic fieldisMagneticFieldSensorAvailablegetMagneticFieldSensorrememberMagneticFieldSensorValueAsState
💨 PressureisPressureSensorAvailablegetPressureSensorrememberPressureSensorValueAsState
🔛 ProximityisProximitySensorAvailablegetProximitySensorrememberProximitySensorValueAsState
💧 Relative HumidityisRelativeHumiditySensorAvailablegetRelativeHumiditySensorrememberRelativeHumiditySensorValueAsState

Watch this space, more types to come!

License

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

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp