Search code examples
androidbattery

Is there a way to make a customView for battery?


Is there a way to make a customView for the battery status?

Like i'm trying to make a kiosk app so the status bar is hided and i'm showing the wi-fi status with the following library, is there a way to make something for the battery or is there yet an existing library for it?


Solution

  • Just register broadcast receiver and get what you need in onReceive

    val receiver = object : BroadcastReceiver() {
            override fun onReceive(context: Context?, intent: Intent?) {
                val battery = intent?.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
            }
            //todo
        }
    
    registerReceiver(receiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED))