package Ġcom . ud acity . util Ċ Ċ import Ġandroid . app . Notification Manager Ċ import Ġandroid . app . Pending Intent Ċ import Ġandroid . app . Task Stack Builder Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroidx . core . app . Notification Compat Ċ import Ġcom . ud acity . R Ċ import Ġcom . ud acity . screens . Detail Activity Ċ import Ġcom . ud acity . screens . MainActivity Ċ Ċ const Ġval ĠCHAN NEL _ ID Ġ= Ġ" channelId " Ċ private Ġconst Ġval ĠNOT IFICATION _ ID Ġ= Ġ 0 Ċ private Ġconst Ġval ĠREQUEST _ CODE Ġ= Ġ 1 9 0 1 Ċ Ċ fun ĠNotification Manager . send Notification ( message : ĠString , Ġapplication Context : ĠContext ) Ġ{ ĊĠĠĠ Ġval Ġpending Intent Ġ= Ġapp Pending Intent ( application Context ) ĊĠĠĠ Ġval Ġdetails Pending Intent : ĠPending Intent ? Ġ= ĊĠĠĠĠĠĠĠ Ġdetails Activity Pending Intent ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġapplication Context , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmessage , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġapplication Context . getString ( R . string . download ing Notification ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠ Ġ// ĠBuild Ġthe Ġnotification ĊĠĠĠ Ġval Ġbuilder Ġ= ĊĠĠĠĠĠĠĠ Ġnotification Builder ( application Context , Ġmessage , Ġpending Intent , Ġdetails Pending Intent ) ĊĊĠĠĠ Ġnotify ( NOTIFICATION _ ID , Ġbuilder . build ()) Ċ } Ċ Ċ private Ġfun Ġdetails Activity Pending Intent ( ĊĠĠĠ Ġapplication Context : ĠContext , ĊĠĠĠ Ġmessage : ĠString , ĊĠĠĠ Ġstatus : ĠString Ċ ): ĠPending Intent ? Ġ{ ĊĠĠĠ Ġval Ġdetails Intent Ġ= ĠIntent ( application Context , ĠDetail Activity :: class . java ) ĊĠĠĠ Ġdetails Intent . putExtra ( Detail Activity . INT ENT _ EXTRA _ FILE _ NAME , Ġmessage ) ĊĠĠĠ Ġdetails Intent . putExtra ( Detail Activity . INT ENT _ EXTRA _ STATUS , Ġstatus ) ĊĠĠĠ Ġreturn ĠTask Stack Builder . create ( application Context ). run Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠAdd Ġthe Ġintent , Ġwhich Ġinfl ates Ġthe Ġback Ġstack ĊĠĠĠĠĠĠĠ Ġadd Next Intent With Parent Stack ( details Intent ) ĊĠĠĠĠĠĠĠ Ġ// ĠGet Ġthe ĠPending Intent Ġcontaining Ġthe Ġentire Ġback Ġstack ĊĠĠĠĠĠĠĠ Ġget Pending Intent ( REQUEST _ CODE , ĠPending Intent . FLAG _ UPDATE _ CURRENT ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ private Ġfun Ġapp Pending Intent ( application Context : ĠContext ): ĠPending Intent ? Ġ{ ĊĠĠĠ Ġval Ġintent Ġ= ĠIntent ( application Context , ĠMainActivity :: class . java ) ĊĠĠĠ Ġreturn ĠPending Intent . getActivity ( ĊĠĠĠĠĠĠĠ Ġapplication Context , ĊĠĠĠĠĠĠĠ ĠNOT IFICATION _ ID , ĊĠĠĠĠĠĠĠ Ġintent , ĊĠĠĠĠĠĠĠ ĠPending Intent . FLAG _ UPDATE _ CURRENT ĊĠĠĠ Ġ) Ċ } Ċ Ċ private Ġfun Ġnotification Builder ( ĊĠĠĠ Ġapplication Context : ĠContext , ĊĠĠĠ Ġmessage : ĠString , ĊĠĠĠ Ġpending Intent : ĠPending Intent ?, ĊĠĠĠ Ġdetails Pending Intent : ĠPending Intent ? Ċ ): ĠNotification Compat . Builder Ġ{ ĊĠĠĠ Ġreturn ĠNotification Compat . Builder ( ĊĠĠĠĠĠĠĠ Ġapplication Context , ĊĠĠĠĠĠĠĠ ĠCHAN NEL _ ID ĊĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ. set Small Icon ( R . drawable . ic _ download ) ĊĠĠĠĠĠĠĠ Ġ. setContent Title ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġapplication Context ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. getString ( R . string . notification _ title ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ. setContent Text ( message ) ĊĠĠĠĠĠĠĠ Ġ. setContent Intent ( pending Intent ). setAuto Cancel ( true ). addAction ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . drawable . ic _ download , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġapplication Context . getString ( R . string . notification _ button ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġdetails Pending Intent ĊĠĠĠĠĠĠĠ Ġ). set Priority ( Notification Compat . PRIORITY _ HIGH ) Ċ } Ċ Ċ fun ĠNotification Manager . update Status ( application Context : ĠContext , Ġmessage : ĠString , Ġstatus : ĠString ) Ġ{ ĊĠĠĠ Ġval Ġpending Intent Ġ= Ġapp Pending Intent ( application Context ) ĊĠĠĠ Ġval Ġdetails Pending Intent : ĠPending Intent ? Ġ= ĊĠĠĠĠĠĠĠ Ġdetails Activity Pending Intent ( application Context , Ġmessage , Ġstatus ) ĊĊĠĠĠ Ġ// ĠBuild Ġthe Ġnotification ĊĠĠĠ Ġval Ġbuilder Ġ= ĊĠĠĠĠĠĠĠ Ġnotification Builder ( application Context , Ġmessage , Ġpending Intent , Ġdetails Pending Intent ) ĊĊĠĠĠ Ġnotify ( NOTIFICATION _ ID , Ġbuilder . build ()) Ċ } Ċ Ċ fun ĠNotification Manager . cancel Notifications () Ġ{ ĊĠĠĠ Ġcancel All () Ċ }