
Unified reactive API for real-time battery health, charging status, and advanced diagnostics (cycle count, current, voltage, temperature), plus plug-and-play UI widgets and developer tools.
🔗 GitHub · 📦 Maven Central · 📖 Blog Post
Volta is the most comprehensive Kotlin Multiplatform battery library for monitoring battery health, charging status, and diagnostics across Android, iOS, Desktop, and Web. Published on Maven Central. Built by Fangga Dewangga.
Volta is a powerful compose multiplatform battery library and Kotlin Multiplatform (KMP) solution designed to simplify hardware monitoring across all major platforms. Whether you need to access battery data in your core business logic (via pure KMP) or build reactive user interfaces (via Compose Multiplatform), Volta provides the right tools. It provides a unified, reactive API to easily access real-time battery health, charging status, and advanced diagnostics across Android, iOS (Arm64 & Apple Silicon), Desktop (JVM), and Web (WasmJs).
Building cross-platform apps with Kotlin Multiplatform is powerful — until you need hardware access. Battery monitoring requires completely different APIs on every platform:
| Platform | Native API | Complexity |
|---|---|---|
| Android |
BatteryManager + BroadcastReceiver
|
Medium |
| iOS | UIDevice.current.batteryLevel |
Low (but limited data) |
| Desktop |
wmic / pmset / /sys/class/
|
High |
| Web | navigator.getBattery() |
Medium (privacy-restricted) |
Volta eliminates this complexity. One dependency, one API, every platform:
// Works everywhere — Android, iOS, Desktop, Web
val sensorState by rememberBatteryState()No expect/actual declarations. No platform modules. Just battery data.
Volta is built to support both pure Kotlin Multiplatform (KMP) projects and modern Compose Multiplatform UI architectures. It offers lightweight, native performance without forcing a UI framework on your business logic.
StateFlow for seamless, real-time integration with your applications.rememberBatteryState() hook and pre-built components for instant UI updates.BatteryManager, iOS UIDevice, Windows WMIC, macOS pmset) for maximum efficiency.Add Volta to your commonMain dependencies in your build.gradle.kts file:
commonMain.dependencies {
// 1. Core Kotlin Multiplatform logic (Required - no UI dependencies)
implementation("io.github.techie-labs:volta:1.0.0")
// 2. Optional: Compose Multiplatform Widgets & State hooks
implementation("io.github.techie-labs:volta-ui-compose:1.0.0")
// Optional: Mock provider for Previews and Unit Tests
implementation("io.github.techie-labs:volta-mock:1.0.0")
}Before using Volta, ensure your platform is correctly configured.
No special permissions are required for basic battery level and status monitoring. However, you must initialize the library.
If you are using Volta in your business logic (ViewModels/Repositories), initialize it in your Application class or MainActivity:
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
VoltaFactory.initialize(this)
}
}[!TIP] If you only use
rememberBatteryState()fromvolta-ui-compose, initialization is handled automatically for you!
Add this to your AndroidManifest.xml if you want to access advanced diagnostics on some devices (though most features work without it):
<uses-permission android:name="android.permission.BATTERY_STATS" />No setup, permissions, or initialization required. It works out of the box! 🚀
The easiest way to get started. No manual initialization required on any platform.
import androidx.compose.runtime.getValue
import io.techie.volta.compose.rememberBatteryState
import io.techie.volta.VoltaSensorState
@Composable
fun BatteryDashboard() {
val sensorState by rememberBatteryState()
when (sensorState) {
is VoltaSensorState.Loading -> Text("Connecting to battery sensor...")
is VoltaSensorState.PermissionDenied -> Text("⚠️ Please grant battery permissions.")
is VoltaSensorState.HardwareNotSupported -> Text("⚠️ Battery sensor not supported on this device.")
is VoltaSensorState.Available -> {
val battery = (sensorState as VoltaSensorState.Available).data
Column {
Text("Battery Level: ${battery.level}%")
Text("Charging Status: ${battery.chargingStatus}")
if (battery.isPowerSavingMode) {
Text("⚠️ Low Power Mode is ON")
}
}
}
else -> Text("Unknown sensor state")
}
}Observe battery changes in your business logic:
import io.techie.volta.VoltaFactory
import io.techie.volta.VoltaSensorState
class BatteryViewModel {
// 1. Create a platform-specific instance via Factory
private val volta = VoltaFactory.create()
init {
// 2. Start monitoring hardware events
volta.startMonitoring()
viewModelScope.launch {
// 3. Collect state safely
volta.batteryState.collect { state ->
if (state is VoltaSensorState.Available) {
println("Current Level: ${state.data.level}%")
}
}
}
}
}If you don't want to build battery UI from scratch, use our plug-and-play components:
import io.techie.volta.ui.VoltaBatteryIcon
import io.techie.volta.ui.ThermalWarningBanner
import io.techie.volta.VoltaSensorState
@Composable
fun BatteryDashboard() {
val sensorState by rememberBatteryState()
if (sensorState is VoltaSensorState.Available) {
val battery = (sensorState as VoltaSensorState.Available).data
Column {
// Dynamic vector icon that fills up and changes color
VoltaBatteryIcon(state = battery, modifier = Modifier.height(32.dp).width(64.dp))
// Auto-appearing banner when device overheats (>= 45°C)
ThermalWarningBanner(state = battery)
}
}
}Volta includes advanced tools to help you build battery-efficient apps.
Safely execute heavy background tasks (like syncing or AI processing) only when hardware conditions are optimal.
import io.techie.volta.devtools.*
val condition = ExecutionCondition(
minBatteryLevel = 20,
requiresCharging = true,
maxTemperatureC = 40.0f
)
// Suspend your coroutine until conditions are met
batteryProvider.whenOptimal(condition) {
// Run your heavy ML model or sync job here
syncData()
}Track battery consumption for specific user sessions or tasks.
import io.techie.volta.devtools.BatteryProfiler
val profiler = BatteryProfiler(batteryProvider)
// Start tracking before a heavy operation
profiler.startSession("VideoProcessing")
// ... do heavy work ...
// Stop tracking and get a comprehensive report
val report = profiler.stopSession("VideoProcessing")
val drop = (report?.startBatteryPercent ?: 0) - (report?.endBatteryPercent ?: 0)
println("Battery dropped by $drop% during video processing.")Get an instant, flat map of all battery states for crash reporting or logging.
import io.techie.volta.diagnostics.getDiagnosticDump
val dump = batteryState.getDiagnosticDump()
// Example: crashlytics.setCustomKeys(dump)Use VoltaMock to simulate hardware states in Compose Previews without physical devices:
import io.techie.volta.mock.VoltaMock
import io.techie.volta.core.BatteryState
import io.techie.volta.VoltaSensorState
@Preview
@Composable
fun LowBatteryPreview() {
val mockVolta = VoltaMock()
mockVolta.setBatteryLevel(10)
mockVolta.setCharging(false)
mockVolta.setPowerSavingMode(true)
// Test the specific UI state explicitly:
val mockState = VoltaSensorState.Available(mockVolta.getBatteryState())
// Provide to your UI component...
}VoltaFactory.initialize(context) for non-compose usage.BATTERY_STATS is optional for advanced diagnostics.wmic and powercfg.pmset and system_profiler./sys/class/power_supply/.navigator.getBattery()).| Feature | Android 🤖 | iOS 🍎 | Windows 🪟 | macOS 🍏 | Web (Wasm) 🌐 |
|---|---|---|---|---|---|
| Level & Status | ✅ | ✅ | ✅ | ✅ | ✅ |
| Power Saving | ✅ | ✅ | ❌ | ❌ | ❌ |
| Voltage | ✅ | ❌ | ❌ | ✅ | ❌ |
| Temperature | ✅ | ❌ | ❌ | ✅ | ❌ |
| Technology | ✅ | ❌ | ❌ | ✅ | ❌ |
| Cycles | ✅ (14+) | ❌ | ✅ | ✅ | ❌ |
| Current (Now) | ✅ | ❌ | ❌ | ✅ | ❌ |
| Safe Mode | ✅ | ❌ | ❌ | ❌ | ❌ |
| Time Remaining | ❌ | ❌ | ❌ | ✅ | ✅ |
| Capacity | ✅ | ❌ | ❌ | ✅ | ❌ |
How does Volta compare to other KMP battery solutions?
| Feature | Volta | KmpEssentials | DeviceKit KMP | multiplatform-utils |
|---|---|---|---|---|
| Pure KMP (no UI dependency) | ✅ | ✅ | ✅ | ✅ |
| Compose Multiplatform widgets | ✅ | ❌ | ❌ | ❌ |
| Desktop (JVM) support | ✅ | ❌ | ❌ | ❌ |
| Web (Wasm) support | ✅ | ❌ | ❌ | ❌ |
| Deep diagnostics (temp, voltage, cycles) | ✅ | ❌ | ✅ | ❌ |
| Smart Sync / Battery Profiler | ✅ | ❌ | ❌ | ❌ |
| Diagnostic Dump (crash reporting) | ✅ | ❌ | ❌ | ❌ |
| Mock provider for testing | ✅ | ❌ | ❌ | ❌ |
| Published on Maven Central | ✅ | ✅ | ❌ | ✅ |
| Reactive StateFlow API | ✅ | ❌ | ❌ | ❌ |
Volta includes comprehensive unit tests for its core logic. The CI pipeline runs these tests on every push to ensure stability.
./gradlew allTestsVolta is a Kotlin Multiplatform (KMP) battery library that provides unified access to battery health, charging status, and diagnostics across Android, iOS, Desktop (Windows, macOS, Linux), and Web (Wasm). The source code is available on GitHub.
Add Volta to your build.gradle.kts file from Maven Central:
implementation("io.github.techie-labs:volta:1.0.0")Yes! Volta provides rememberBatteryState() and pre-built UI widgets via the volta-ui-compose module. See the Usage section for examples.
Volta supports Android (Min SDK 24), iOS (Arm64), Desktop (JVM — Windows, macOS, Linux), and Web (WasmJs).
Yes. Volta is open-source software licensed under the Apache 2.0 License.
Volta was created by Fangga Dewangga and is maintained under the Techie Labs organization.
Contributions are welcome! Please read our CONTRIBUTING.md to get started.
Volta is open-source software licensed under the Apache 2.0 License.
Built with ⚡ by Techie Labs · Created by Fangga Dewangga
🔗 GitHub · 📦 Maven Central · 📖 Blog Post
Volta is the most comprehensive Kotlin Multiplatform battery library for monitoring battery health, charging status, and diagnostics across Android, iOS, Desktop, and Web. Published on Maven Central. Built by Fangga Dewangga.
Volta is a powerful compose multiplatform battery library and Kotlin Multiplatform (KMP) solution designed to simplify hardware monitoring across all major platforms. Whether you need to access battery data in your core business logic (via pure KMP) or build reactive user interfaces (via Compose Multiplatform), Volta provides the right tools. It provides a unified, reactive API to easily access real-time battery health, charging status, and advanced diagnostics across Android, iOS (Arm64 & Apple Silicon), Desktop (JVM), and Web (WasmJs).
Building cross-platform apps with Kotlin Multiplatform is powerful — until you need hardware access. Battery monitoring requires completely different APIs on every platform:
| Platform | Native API | Complexity |
|---|---|---|
| Android |
BatteryManager + BroadcastReceiver
|
Medium |
| iOS | UIDevice.current.batteryLevel |
Low (but limited data) |
| Desktop |
wmic / pmset / /sys/class/
|
High |
| Web | navigator.getBattery() |
Medium (privacy-restricted) |
Volta eliminates this complexity. One dependency, one API, every platform:
// Works everywhere — Android, iOS, Desktop, Web
val sensorState by rememberBatteryState()No expect/actual declarations. No platform modules. Just battery data.
Volta is built to support both pure Kotlin Multiplatform (KMP) projects and modern Compose Multiplatform UI architectures. It offers lightweight, native performance without forcing a UI framework on your business logic.
StateFlow for seamless, real-time integration with your applications.rememberBatteryState() hook and pre-built components for instant UI updates.BatteryManager, iOS UIDevice, Windows WMIC, macOS pmset) for maximum efficiency.Add Volta to your commonMain dependencies in your build.gradle.kts file:
commonMain.dependencies {
// 1. Core Kotlin Multiplatform logic (Required - no UI dependencies)
implementation("io.github.techie-labs:volta:1.0.0")
// 2. Optional: Compose Multiplatform Widgets & State hooks
implementation("io.github.techie-labs:volta-ui-compose:1.0.0")
// Optional: Mock provider for Previews and Unit Tests
implementation("io.github.techie-labs:volta-mock:1.0.0")
}Before using Volta, ensure your platform is correctly configured.
No special permissions are required for basic battery level and status monitoring. However, you must initialize the library.
If you are using Volta in your business logic (ViewModels/Repositories), initialize it in your Application class or MainActivity:
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
VoltaFactory.initialize(this)
}
}[!TIP] If you only use
rememberBatteryState()fromvolta-ui-compose, initialization is handled automatically for you!
Add this to your AndroidManifest.xml if you want to access advanced diagnostics on some devices (though most features work without it):
<uses-permission android:name="android.permission.BATTERY_STATS" />No setup, permissions, or initialization required. It works out of the box! 🚀
The easiest way to get started. No manual initialization required on any platform.
import androidx.compose.runtime.getValue
import io.techie.volta.compose.rememberBatteryState
import io.techie.volta.VoltaSensorState
@Composable
fun BatteryDashboard() {
val sensorState by rememberBatteryState()
when (sensorState) {
is VoltaSensorState.Loading -> Text("Connecting to battery sensor...")
is VoltaSensorState.PermissionDenied -> Text("⚠️ Please grant battery permissions.")
is VoltaSensorState.HardwareNotSupported -> Text("⚠️ Battery sensor not supported on this device.")
is VoltaSensorState.Available -> {
val battery = (sensorState as VoltaSensorState.Available).data
Column {
Text("Battery Level: ${battery.level}%")
Text("Charging Status: ${battery.chargingStatus}")
if (battery.isPowerSavingMode) {
Text("⚠️ Low Power Mode is ON")
}
}
}
else -> Text("Unknown sensor state")
}
}Observe battery changes in your business logic:
import io.techie.volta.VoltaFactory
import io.techie.volta.VoltaSensorState
class BatteryViewModel {
// 1. Create a platform-specific instance via Factory
private val volta = VoltaFactory.create()
init {
// 2. Start monitoring hardware events
volta.startMonitoring()
viewModelScope.launch {
// 3. Collect state safely
volta.batteryState.collect { state ->
if (state is VoltaSensorState.Available) {
println("Current Level: ${state.data.level}%")
}
}
}
}
}If you don't want to build battery UI from scratch, use our plug-and-play components:
import io.techie.volta.ui.VoltaBatteryIcon
import io.techie.volta.ui.ThermalWarningBanner
import io.techie.volta.VoltaSensorState
@Composable
fun BatteryDashboard() {
val sensorState by rememberBatteryState()
if (sensorState is VoltaSensorState.Available) {
val battery = (sensorState as VoltaSensorState.Available).data
Column {
// Dynamic vector icon that fills up and changes color
VoltaBatteryIcon(state = battery, modifier = Modifier.height(32.dp).width(64.dp))
// Auto-appearing banner when device overheats (>= 45°C)
ThermalWarningBanner(state = battery)
}
}
}Volta includes advanced tools to help you build battery-efficient apps.
Safely execute heavy background tasks (like syncing or AI processing) only when hardware conditions are optimal.
import io.techie.volta.devtools.*
val condition = ExecutionCondition(
minBatteryLevel = 20,
requiresCharging = true,
maxTemperatureC = 40.0f
)
// Suspend your coroutine until conditions are met
batteryProvider.whenOptimal(condition) {
// Run your heavy ML model or sync job here
syncData()
}Track battery consumption for specific user sessions or tasks.
import io.techie.volta.devtools.BatteryProfiler
val profiler = BatteryProfiler(batteryProvider)
// Start tracking before a heavy operation
profiler.startSession("VideoProcessing")
// ... do heavy work ...
// Stop tracking and get a comprehensive report
val report = profiler.stopSession("VideoProcessing")
val drop = (report?.startBatteryPercent ?: 0) - (report?.endBatteryPercent ?: 0)
println("Battery dropped by $drop% during video processing.")Get an instant, flat map of all battery states for crash reporting or logging.
import io.techie.volta.diagnostics.getDiagnosticDump
val dump = batteryState.getDiagnosticDump()
// Example: crashlytics.setCustomKeys(dump)Use VoltaMock to simulate hardware states in Compose Previews without physical devices:
import io.techie.volta.mock.VoltaMock
import io.techie.volta.core.BatteryState
import io.techie.volta.VoltaSensorState
@Preview
@Composable
fun LowBatteryPreview() {
val mockVolta = VoltaMock()
mockVolta.setBatteryLevel(10)
mockVolta.setCharging(false)
mockVolta.setPowerSavingMode(true)
// Test the specific UI state explicitly:
val mockState = VoltaSensorState.Available(mockVolta.getBatteryState())
// Provide to your UI component...
}VoltaFactory.initialize(context) for non-compose usage.BATTERY_STATS is optional for advanced diagnostics.wmic and powercfg.pmset and system_profiler./sys/class/power_supply/.navigator.getBattery()).| Feature | Android 🤖 | iOS 🍎 | Windows 🪟 | macOS 🍏 | Web (Wasm) 🌐 |
|---|---|---|---|---|---|
| Level & Status | ✅ | ✅ | ✅ | ✅ | ✅ |
| Power Saving | ✅ | ✅ | ❌ | ❌ | ❌ |
| Voltage | ✅ | ❌ | ❌ | ✅ | ❌ |
| Temperature | ✅ | ❌ | ❌ | ✅ | ❌ |
| Technology | ✅ | ❌ | ❌ | ✅ | ❌ |
| Cycles | ✅ (14+) | ❌ | ✅ | ✅ | ❌ |
| Current (Now) | ✅ | ❌ | ❌ | ✅ | ❌ |
| Safe Mode | ✅ | ❌ | ❌ | ❌ | ❌ |
| Time Remaining | ❌ | ❌ | ❌ | ✅ | ✅ |
| Capacity | ✅ | ❌ | ❌ | ✅ | ❌ |
How does Volta compare to other KMP battery solutions?
| Feature | Volta | KmpEssentials | DeviceKit KMP | multiplatform-utils |
|---|---|---|---|---|
| Pure KMP (no UI dependency) | ✅ | ✅ | ✅ | ✅ |
| Compose Multiplatform widgets | ✅ | ❌ | ❌ | ❌ |
| Desktop (JVM) support | ✅ | ❌ | ❌ | ❌ |
| Web (Wasm) support | ✅ | ❌ | ❌ | ❌ |
| Deep diagnostics (temp, voltage, cycles) | ✅ | ❌ | ✅ | ❌ |
| Smart Sync / Battery Profiler | ✅ | ❌ | ❌ | ❌ |
| Diagnostic Dump (crash reporting) | ✅ | ❌ | ❌ | ❌ |
| Mock provider for testing | ✅ | ❌ | ❌ | ❌ |
| Published on Maven Central | ✅ | ✅ | ❌ | ✅ |
| Reactive StateFlow API | ✅ | ❌ | ❌ | ❌ |
Volta includes comprehensive unit tests for its core logic. The CI pipeline runs these tests on every push to ensure stability.
./gradlew allTestsVolta is a Kotlin Multiplatform (KMP) battery library that provides unified access to battery health, charging status, and diagnostics across Android, iOS, Desktop (Windows, macOS, Linux), and Web (Wasm). The source code is available on GitHub.
Add Volta to your build.gradle.kts file from Maven Central:
implementation("io.github.techie-labs:volta:1.0.0")Yes! Volta provides rememberBatteryState() and pre-built UI widgets via the volta-ui-compose module. See the Usage section for examples.
Volta supports Android (Min SDK 24), iOS (Arm64), Desktop (JVM — Windows, macOS, Linux), and Web (WasmJs).
Yes. Volta is open-source software licensed under the Apache 2.0 License.
Volta was created by Fangga Dewangga and is maintained under the Techie Labs organization.
Contributions are welcome! Please read our CONTRIBUTING.md to get started.
Volta is open-source software licensed under the Apache 2.0 License.
Built with ⚡ by Techie Labs · Created by Fangga Dewangga