As you know this is how we fire a JobIntentService
:
JobIntentService.enqueueWork(this,
MyJobIntentService.class,
JOB_ID,
intent);
In this approach we KNOW which service we want to start and pass its class to the method.
Here is my question: Is there any way to start a service implicitly ?
Why I need this ? I'm developing a library that sometimes should start a service that developer extends and obviously I have no access to it from library
What I tried? I implemented it with IntentService
(using intent filters) and worked fine for pre O devices but for Android Oreo I'm receiving this crash log:
Fatal Exception: java.lang.IllegalStateException: Not allowed to start service Intent { act=someAction pkg=somePackage (has extras) }: app is in background uid UidRecord{de24eda u0a238 RCVR idle procs:1 seq(0,0,0)}
So I moved to JobIntentService
, now the problem is that I can't start it implicitly.
Any solution or alternative will be appreciated.
Well, I found a solution, first query for service you're looking for and check if has the necessary permission for
JobIntentService
, then enqueue work :And in app module manifest I added
android.permission.BIND_JOB_SERVICE
to my service as well: