package Ġcom . er man . battery Ċ Ċ import Ġandroid . content . Broadcast Receiver Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . os . Battery Manager Ċ import Ġandroid . os . Bundle Ċ Ċ class ĠBroadcast Receiver () Ġ: ĠBroadcast Receiver () Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlistener : ĠBroadcast Receiver Listener ĊĊĠĠĠ Ġoverride Ġfun Ġon Receive ( context : ĠContext ?, Ġintent : ĠIntent ?) Ġ{ ĊĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlistener Ġ= Ġcontext Ġas ĠBroadcast Receiver Listener ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( err : ĠClass CastException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠClass CastException ( ("$ context Ġmust Ġimplement ĠBroadcast Receiver Listener ")) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġbattery Percentage Ġ= Ġintent ?. getInt Extra ( Battery Manager . EXTRA _ LEVEL , Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġvoltage Ġ= Ġintent ?. getInt Extra ( Battery Manager . EXTRA _ VOL T AGE , Ġ 0 )?. toFloat () ĊĠĠĠĠĠĠĠ Ġval Ġbattery Temp Ġ= Ġintent ?. getInt Extra ( Battery Manager . EXTRA _ TEMP ER ATURE , Ġ 0 )?. toFloat ()?. div ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġch arging Status Ġ= Ġintent ?. getInt Extra ( Battery Manager . EXTRA _ PLU GG ED , Ġ- 1 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġbundle Ġ= ĠBundle () ĊĊĠĠĠĠĠĠĠ Ġbattery Percentage ?. let Ġ{ Ġbundle . put Int ( KEY _ B UNDLE _ B ATTER Y _ PERCENT AGE , Ġit ) Ġ} ĊĠĠĠĠĠĠĠ Ġvoltage ?. let Ġ{ Ġbundle . put Float ( KEY _ B UNDLE _ B ATTER Y _ VOL T AGE , Ġit ) Ġ} ĊĠĠĠĠĠĠĠ Ġbattery Temp ?. let Ġ{ Ġbundle . put Float ( KEY _ B UNDLE _ B ATTER Y _ TEMP , Ġit ) Ġ} ĊĠĠĠĠĠĠĠ Ġch arging Status ?. let Ġ{ Ġbundle . put Int ( KEY _ B UNDLE _ CHAR GING _ STATUS , Ġit ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġlistener . broadcast Receiver Listener ( bundle ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinterface ĠBroadcast Receiver Listener Ġ{ ĊĠĠĠĠĠĠĠ Ġfun Ġbroadcast Receiver Listener ( bundle : ĠBundle ) ĊĠĠĠ Ġ} Ċ Ċ }