title: Android BroadcastReceiver unable to receive Screen_On and Screen_Off broadcasts
body: <p>I am trying to get my BroadcastReceiver, created inside of a service, to receive Screen_On and Screen_Off events. It is not working, here is what I am trying right now.</p>
  
  <pre><code>//OnCreate Method for the service
  @Override
  public void onCreate() {
      super.onCreate();
      myBroadcast = new MyBroadcastReceiver();
      IntentFilter screenOn_Off = new IntentFilter();
      screenOn_Off.addAction(Intent.ACTION_SCREEN_OFF);
      screenOn_Off.addAction(Intent.ACTION_SCREEN_ON);
      registerReceiver(myBroadcast, screenOn_Off);
  }
  
  //Inner class for the broadcast receiver, also in the service.
  public class MyBroadcastReceiver extends BroadcastReceiver{
      @Override
      public void onReceive(Context context, Intent intent) {
          Log.d("Broadcast received", "Broadcast received");
  
          if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)){
              startTimers();
          } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){
              screenLocked();
          }
      }
  };
  
  //Declaration of receiver in manifest.
          &lt;receiver
          android:name="com.bla.bla.bla$MyBroadcastReceiver"
          android:enabled="true"&gt;
          &lt;/receiver&gt;
  </code></pre>
  
  <p>I purposely did not include the intent filters for the screen_on and off because I read that those must be declared programmatically, including them made not difference.</p>