2

I have to listen a custom broadcast receiver that has registered in a AndroidManifest.xml, but now it doesn't work in Android O. I was given an advise that use JobScheduler API to solve this problem. I have looked at many docs and blogs, they just tell me how to use JobScheduler to replace system broadcast receiver that registered in AndroidManifest.xml, such as network status change. But I can not find a way to use JobScheduler to listen a custom broadcast receiver, any one who can help me?

coder.john
  • 1,235
  • 2
  • 12
  • 11
  • What exactly do you mean by "custom broadcast receiver"? Do you mean a `` for some custom broadcast action? If so, what other apps are sending that broadcast? – CommonsWare Aug 13 '18 at 12:04
  • @CommonsWare Yes, I mean that. And other app will send broadcast like this: `sendBroadcast(new Intent("com.tcl.mediainfo.trace"));` Also this implicit broadcast is hardly to be modified to be explicit. – coder.john Aug 13 '18 at 12:30

1 Answers1

0

JobScheduler does not help in this scenario.

The authors of the app that is sending the broadcast need to update their app to either:

  • Send an explicit broadcast, or

  • Do something else for IPC (e.g., use a bound service)

In the meantime, your only option to receive those broadcasts is to register for them using registerReceiver(). That only works while you have a running process, so if you are expecting to receive the broadcasts most of the time, you will need a foreground service.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • My app will not always keep running for performance optimization, I just want to wake up my app when receives the broadcast. Once the app finishes the work, it will be stopped. – coder.john Aug 14 '18 at 01:09
  • @coder.john: Then you need to convince the authors of the other app to change their app. – CommonsWare Aug 14 '18 at 11:48
  • Any solutions for this case? I have the same problem and being struggling with this for 3 days. I've tried invisible Activity + context Broadcast Receivers, Service + context Broadcast Receivers and a simple JobScheduler with no luck. Thanks in advance. – Carlos Jiménez Jun 14 '22 at 23:49
  • @CarlosJiménez: As I noted in the answer, a foreground service should work. – CommonsWare Jun 15 '22 at 11:15