title: "IntentReceiver components are not allowed to register to receive intents" when trying to determine Battery level
body: <p>I am trying to get Battery info from my Application following the guidelines at <a href="http://developer.android.com/training/monitoring-device-state/battery-monitoring.html">http://developer.android.com/training/monitoring-device-state/battery-monitoring.html</a></p>
  
  <p>This is the method is came up with to check the battery level:</p>
  
  <pre><code>public void sendBatteryInfoMessage(){
  
      IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
      Intent batteryStatus = c.registerReceiver(null, iFilter);
  
      int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
      boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL;
  
      int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
      boolean isUsbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
      boolean isAcCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
  
      int batteryLevel = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
      int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
  
      float batteryPct = batteryLevel / (float) scale;
  
  }
  </code></pre>
  
  <p><code>c</code> is initialized as <code>Context</code> object earlier in the class.</p>
  
  <p>This is the error message I am getting </p>
  
  <pre><code>    07-24 18:11:23.445      634-634/wifi.myapp.sudara.lk.sudara_app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40028890)
  07-24 18:11:23.485      634-634/wifi.myapp.sudara.lk.sudara_app E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.RuntimeException: Unable to start receiver wifi.myapp.sudara.lk.sudara_app.SmsActivity: android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents
              at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
              at android.app.ActivityThread.access$3200(ActivityThread.java:125)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:123)
              at android.app.ActivityThread.main(ActivityThread.java:4627)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:521)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
              at dalvik.system.NativeStart.main(Native Method)
       Caused by: android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents
              at android.app.ReceiverRestrictedContext.registerReceiver(ContextImpl.java:138)
              at android.app.ReceiverRestrictedContext.registerReceiver(ContextImpl.java:132)
              at wifi.myapp.sudara.lk.sudara_app.BatteryInfo.sendBatteryInfoMessage(BatteryInfo.java:25)
              at wifi.myapp.sudara.lk.sudara_app.SmsActivity.onReceive(SmsActivity.java:53)
              at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
              at android.app.ActivityThread.access$3200(ActivityThread.java:125)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
              at android.os.Handler.dispatchMessage(Handler.java:99)
              at android.os.Looper.loop(Looper.java:123)
              at android.app.ActivityThread.main(ActivityThread.java:4627)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:521)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>What I need to know is the meaning of <code>IntentReceiver components are not allowed to register to receive intents</code> and how to over come it. </p>
  
  <p>Thank you</p>