Skip to content

Instantly share code, notes, and snippets.

@mizutori
Created January 6, 2019 13:42
Show Gist options
  • Save mizutori/c36fe30ab0547c8abd98a51a6980fe40 to your computer and use it in GitHub Desktop.
Save mizutori/c36fe30ab0547c8abd98a51a6980fe40 to your computer and use it in GitHub Desktop.
val batteryInfoReceiver = object : BroadcastReceiver() {
override fun onReceive(ctxt: Context, intent: Intent) {
val batteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
val scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
val batteryLevelScaled = batteryLevel / scale.toFloat()
batteryLevelArray.add(Integer.valueOf(batteryLevel))
batteryLevelScaledArray.add(java.lang.Float.valueOf(batteryLevelScaled))
batteryScale = scale
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment