title: Open app on number of clicks of power button using broadcast receiver
body: <p>I am trying to generate some log and put up a toast on screen after power button click.
  But it doesn't seem to work. Here's the code:</p>
  
  <p>AndroidManifest.xml:</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.test.pbtest"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="17" /&gt;
  
  &lt;uses-permission android:name="android.permission.ACTION_SHUTDOWN" /&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.test.pbtest.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="com.test.pbtest.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>MyReceiver.java class:</p>
  
  <pre><code>package com.test.pbtest;
  
  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 arg0, Intent arg1) {
      // TODO Auto-generated method stub
      Log.v("Hurray!", "Power button was clicked!");
          Toast.makeText(arg0, "power button clicked",Toast.LENGTH_LONG).show();
  }
  
  }
  </code></pre>
  
  <p>MainActivity.java class:</p>
  
  <pre><code>package com.test.pbtest;
  
  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.activity_main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>As per my knowledge, i need not register my receiver explicitly as i have used it in manifest file. Please guide me where i am going wrong.</p>