title: Android: Wake & unlock phone
body: <p>I am trying to figure out how to wake and unlock the phone with a service. I have been referring to <a href="https://stackoverflow.com/questions/3621599/wake-android-device-up">this</a> post but, I can't figure out why it isn't working. This is the code that I have so far:</p>
  
  <pre><code>public class WakephoneActivity extends Activity {
  
      BroadcastReceiver mReceiver;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          mReceiver = new BroadcastReceiver() {
  
              @Override
              public void onReceive(Context context, Intent intent) {
                  // Log.v(TAG, "Screen OFF onReceive()");
                  screenOFFHandler.sendEmptyMessageDelayed(0, 2000);
              }
          };
      }
  
      private Handler screenOFFHandler = new Handler() {
  
          @Override
          public void handleMessage(Message msg) {
              super.handleMessage(msg);
              // do something
              // wake up phone
              // Log.i(TAG, "ake up the phone and disable keyguard");
              PowerManager powerManager = (PowerManager) WakephoneActivity.this
                      .getSystemService(Context.POWER_SERVICE);
              long l = SystemClock.uptimeMillis();
              powerManager.userActivity(l, false);// false will bring the screen
              // back as bright as it was, true - will dim it
          }
      };
  
      protected void onResume() {
          super.onResume();
          IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
          registerReceiver(mReceiver, filter);
          // Log.i(TAG, "broadcast receiver registered!");
      }
  }
  </code></pre>
  
  <p>I have added the code in the manifest as well. Any ideas?</p>