title: Receiving Power Connection event
body: <p>I am trying to learn android on my own, and currently working on a simple project.</p>
  
  <p>I want to receive whenever the phone is plugged to a power source, so I put a receiver to the manifest and create a subclass under my main activity. The problem is the program crashes when I plug the phone.</p>
  
  <p>There are many questions about it here and everywhere else, and believe me I looked all of them but none of them solved this problem.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>public class MySystemBroadcastReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          Toast.makeText(context, "ACTION_POWER_CONNECTED event received", Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  
  <p>Manifest:</p>
  
  <pre><code>    &lt;receiver
          android:name="deneme.sarjolcer.MainActivity$MySystemBroadcastReceiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.ACTION_POWER_CONNECTED" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>Please forgive me if there is a too silly error, I am just new at this thing. I have been working over the same error for a week now and actually do not see straight now. Thank you very much.</p>