Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using intent broadcast USER_PRESENT in Android O

Tags:

android

Since O is more enforcing background services, how can I receive a broadcast of USER_PRESENT when targeting 26+ ?

Logcat :

system_process W/BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.USER_PRESENT flg=0x24200010 } to fr.cab13140.nullcontactdeleter/.BootThread
like image 337
defvs Daniel Avatar asked Jun 29 '17 14:06

defvs Daniel


People also ask

What is broadcasting intent in Android?

The Android system automatically sends broadcasts when various system events occur, such as when the system switches in and out of airplane mode. The system sends these broadcasts to all apps that are subscribed to receive the event.

What is the difference between intent and broadcast receiver?

An intent is a messaging object, a broadcast receiver is an app component. An intent is used to request some action from some app component, it could be a broadcast receiver, an activity or a service.

Which are the broadcast receivers are available in Android?

There are two types of broadcast receivers: Static receivers, which you register in the Android manifest file. Dynamic receivers, which you register using a context.


1 Answers

The only way to receive that broadcast is by having a running process, where you have used registerReceiver() to register your receiver. If you are trying to listen to this broadcast all of the time, the closest that you will get will be to have a foreground sticky service, to try to maximize the amount of time your service is running. Note that users may not appreciate this.

like image 162
CommonsWare Avatar answered Oct 29 '22 23:10

CommonsWare