BroadcastReceiver onReceive is not getting called

android, broadcastreceiver

Solution

The action you have to intercept is:

<intent-filter>
  <action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>

Developer Android ACTION_USER_PRESENT

Problem

I have defined a BroadCastReceiver in AndroidManifest.xml as below ``` <receiver android:name="com.example.hello.ScreenUnlockReceiver" android:enabled="true" android:singleUser="true"> <intent-filter> <action android:name="android.content.Intent.ACTION_USER_PRESENT" /> </intent-filter> </receiver> ``` and defined the Receiver as below : ``` public class ScreenUnlockReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //start activity Intent i = new Intent(); i.setClassName("com.example.hello", "LoginActivity"); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } } ``` But the broadcastreceiver is not triggered when I unlock the screen and the LoginActivity is not being shown. LoginActivity is the default loginactivity which comes with android sdk. Am I missing something in uses-permission or something else, please let me know. Thanks Santhosh

Original source