title: how to start the app on power button press
body: <p>I want to start my app when a user press the power button. I m following <a href="https://stackoverflow.com/questions/8940922/activate-an-application-when-a-power-button-is-clicked">This code</a>
  but its not showing any <code>Log</code> and toast.</p>
  
  <p>here is my complete code. </p>
  
  <p><strong>MyReceiver.java</strong></p>
  
  <pre><code>import android.content.BroadcastReceiver;
     import android.content.Context;
     import android.content.Intent;
     import android.util.Log;
     import android.widget.Toast;
  
     public class MyReceiver extends BroadcastReceiver {
  
  @Override
  public void onReceive(Context context, Intent intent) {
  
      // TODO Auto-generated method stub
  
      Log.v("onReceive", "Power button is pressed.");
  
      Toast.makeText(context, "power button clicked", Toast.LENGTH_LONG)
              .show();
  
      // perform what you want here
  
  }
  
  }
  </code></pre>
  
  <p><strong>menifest File</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.powerbuttontest"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="17" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.example.powerbuttontest.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;receiver android:name=".MyReceiver" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.SCREEN_OFF" &gt;
              &lt;/action&gt;
              &lt;action android:name="android.intent.action.SCREEN_ON" &gt;
              &lt;/action&gt;
              &lt;action android:name="android.intent.action.ACTION_POWER_CONNECTED" &gt;
              &lt;/action&gt;
              &lt;action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" &gt;
              &lt;/action&gt;
              &lt;action android:name="android.intent.action.ACTION_SHUTDOWN" &gt;
              &lt;/action&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>package com.example.powerbuttontest;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  
  public class MainActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  }
  </code></pre>
  
  <ul>
  <li>I think i m committing a mistake in my <code>menifest file</code>.  please have a look on this. thanks.</li>
  </ul>