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>
My receiver Class:
public class VoiceLaunchReceiver extends android.content.BroadcastReceiver {
@Override
public void onReceive(Context ctx, Intent intent) {
Intent service = new Intent(ctx, VoiceLaunchService.class);
// service.putExtra(action, true);
Log.i("joscsr","Incoming Voice Launch Broadcast...");
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Log.e("joshcsr", "***********\nCSR Resumed (BC)\n************");
ctx.startService(service);
}
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Log.e("joshcsr", "***********\nCSR STOPPED by SCREEN (BC)\n************");
ctx.stopService(service);
}
}
}
I registered the SCREEN_OFF intent in the onCreate method of a service:
@Override
public void onCreate() {
super.onCreate();
//Register screen OFF BroadCast
IntentFilter mIntentFilter=new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(speechBroadcastReceiver, mIntentFilter);
}
It does its thing whenever the user unblocks and turns on the screen. It works perfectly in Jellybean 4.3 and lower: my Logcats inside my Broadcast receiver are shown whenever the screen is locked pr unlocked. Why won't this exact code won't work in Lollipop? Are there new Intents that I must listen to instead?
(I already know that the systems send that intent, what I want is to detect it with my receiver)