I see that multiple broadcasts (ACTION_TIME_TICK, for example) cannot be registered in the manifest, the must be explicitly registered via Context.registerReceiver()
. I am having trouble with the ACTION_USER_PRESENT broadcast intent. Specifically, I test on the emulator and my application keeps force closing with the error:
08-30 09:44:23.397: ERROR/AndroidRuntime(290): java.lang.RuntimeException: Unable to start receiver me.turnerha.RegisterListeners: java.lang.IllegalArgumentException: Receiver not registered: me.turnerha.RegisterListeners@43d05690
This is caused by
08-30 09:44:23.397: ERROR/AndroidRuntime(290): Caused by: java.lang.IllegalArgumentException: Receiver not registered: me.turnerha.RegisterListeners@43d05690
My manifest is fairly simple:
<receiver android:name=".RegisterListeners">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
</intent-filter>
</receiver>
Any thoughts? I am essentially attempting to create a Receiver that is awakened as soon as possible after my application is installed. The first time it is awakened, it registers a few listeners, and then it unregisters itself so it is never called again. (I really wish there was an intent fired immediately after your app had been installed, to allow a small bit of setup :) )
I had the same problem and I fixed it (tested on 4.3 and 5.1). I WAS able to declare "android.intent.action.USER_PRESENT" inside the manifest, as long as you have the READ_PHONE_STATE permission, it is OK!! My mini app consists of a Broadcast receiver that reacts to the screen ON/OFF state, and runs a background service that does continuous voice recognition. If the screen is off, the recognition is turned off. Here is the code, enjoy: MANIFEST:
BROADCAST RECEIVER:
As you can imagine, my USER_PRESENT broadcast receiver is not registered anywhere else. I do register ACTION_SCREEN_OFF and ON in the onCreate method of my service, who was triggered by my receiver.
Finally I unregister the screen on/off in the onDestroy() of my service:
registering ACTION_USER_PRESENT in manifest file does not get triggered always. In my nexus4 if i register ACTION_USER_PRESENT in manifest file then it does not work at all whereas registering in Activity works fine.
Correct -- neither
ACTION_SCREEN_ON
norACTION_USER_PRESENT
can be registered in the manifest. I have filed a documentation bug on this issue.Eitherway, you could use
context.registerReceiver()
which will do the trick, and keep your manifest clean. Link