3

I have this broadcast receiver declared in the Manifest:

    <receiver android:name="classes.VoiceLaunchReceiver" >
        <intent-filter>
            <action android:name="android.intent.action.USER_PRESENT" />
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

It does its thing whenever the user unblock and turns on the screen. It works perfectly in Jellybean 4.3 and lower. Why won't it work in Lollipop?

(I already know that the systems send that intent, what I want is to detect it with my receiver)

Taryn
  • 242,637
  • 56
  • 362
  • 405
Josh
  • 6,251
  • 2
  • 46
  • 73
  • It could be a framework bug, but there haven't been any other reports of this issue. It could also be that `Intent.ACTION_USER_PRESENT` has several caveats: *1)* It is only sent when the user unlocks the Keyguard. If they do not have a lock screen, this intent is never sent. *2)* If the user unlocks their device before boot, it is only sent to registered receivers. No `BroadcastReceiver` components will be launched. – alanv Mar 17 '15 at 00:29
  • Your rant about why this doesn't work shouldn't be included in your post. For the time being, this is locked while you cool off. If you have questions, then take it to Meta. – Taryn Mar 17 '15 at 01:51
  • 1
    You might need to give some more details. This works perfectly for me running Lollipop on a Nexus 4. I just created a new Hello World activity, added your receiver declaration to the Manifest, created a receiver that just logs intent.getAction(), run the app, lock the screen, unlock the screen, and voila, onReceive gets called and action logged. Maybe create an http://stackoverflow.com/help/mcve yourself and see where it gets you, – ci_ Mar 26 '15 at 09:01
  • @ci_ Hi, check out my answer below, you are right. – Josh Mar 26 '15 at 09:17
  • @ci_ please take a look at my question http://stackoverflow.com/q/41032943/6852390 – Mr.Popular Dec 08 '16 at 06:59

1 Answers1

1

Ok, I solved the issue by adding two things: a permission, and a category tag inside the receiver's intent Filter. Everything in the manifest:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
        <receiver android:name="classes.VoiceLaunchReceiver" >        
             <intent-filter>
                <action android:name="android.intent.action.USER_PRESENT" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

Sometime when I was trying to make my own project, I did not see that the original Android demo had the permission.

Josh
  • 6,251
  • 2
  • 46
  • 73
  • I did not need the permission nor the category. I had to remove `exported="false"` from the receiver though. Tested on stock Android 5 – OneWorld Feb 12 '16 at 09:12
  • I did not have exported=false to begin with... @OneWorld – Josh Feb 16 '16 at 10:25
  • I just wanted to say, my receiver worked without declaring the category and permission. Googles docs also don't say anything about the permission. However, removing `exported="false"` solved it for me on Lollipop stock – OneWorld Feb 16 '16 at 11:31