Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To fix context.getSystemService(class) for api 21?

I was following the video for JobScheduler:

https://www.youtube.com/watch?v=XFN3MrnNhZA

But lint was giving me that context.getSystemService(class) is api 23. So am I missing something or did android change something with there api?

Note: Mostly wondering if JobScheduler was introduced in api 21 how would it work without getSystemService(Class)

Thanks.

like image 201
Mohammad Tabbara Avatar asked Dec 14 '17 13:12

Mohammad Tabbara


2 Answers

Came here with a similar problem for NotificationManager. What I ended up doing was

 val notificationManager =
                ContextCompat.getSystemService(
                    requireContext(),
                    NotificationManager::class.java
                ) as NotificationManager
like image 163
Peter Nguyen Avatar answered Oct 25 '22 15:10

Peter Nguyen


Thanks to Reghunandan I found a better solution for my problem by using:

github.com/firebase/firebase-jobdispatcher-android

But if any body got same problem here is the mistake:

getSystemService(Class) API 23

Should be:

getSystemService(String) API 1

getSystemService(context.JOB_SCHEDULER_SERVICE) API 21
like image 31
Mohammad Tabbara Avatar answered Oct 25 '22 16:10

Mohammad Tabbara