Battery changed broadcast receiver crashing app on some phones
<p>I activate my application whenever the phone get plugged in a power source.
This is my manifest</p>

<pre><code>&lt;receiver android:name=".PowerConnectionReceiver"&gt;
      &lt;intent-filter&gt;
        &lt;action android:name="android.intent.action.ACTION_POWER_CONNECTED"/&gt;
        &lt;action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/&gt;
      &lt;/intent-filter&gt;
    &lt;/receiver&gt;
</code></pre>

<p>This is my broadcast receiver</p>

<pre><code>  @Override
    public void onReceive(Context context, Intent intent) {
        Log.w("TAG", "Just received connection broadcast");


        IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
        Intent batteryStatus = context.registerReceiver(null, ifilter); //this line is causing the crash


        int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, 0);
</code></pre>

<p>Now, the line causing the crashing on my friends phone (on mine everything is working perfectly) is this one</p>

<pre><code>Intent batteryStatus = context.registerReceiver(null, ifilter);
</code></pre>

<p>Can someone please tell me what is the reason and how to fix it?
My phone is a galaxy nexus with the latest android JB, his phone is a LG optimus one with gingerbread</p>

<p>Here is the logcat</p>

<pre><code>    02-27 01:25:19.399: D/AndroidRuntime(5326): Shutting down VM
02-27 01:25:19.399: W/dalvikvm(5326): threadid=1: thread exiting with uncaught exception (group=0x40018560)
02-27 01:25:19.419: E/AndroidRuntime(5326): FATAL EXCEPTION: main
02-27 01:25:19.419: E/AndroidRuntime(5326): java.lang.RuntimeException: Unable to start receiver com.doublep.wakey.PowerConnectionReceiver: android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:1926)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.app.ActivityThread.access$2400(ActivityThread.java:123)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:989)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.os.Looper.loop(Looper.java:130)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.app.ActivityThread.main(ActivityThread.java:3835)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at java.lang.reflect.Method.invokeNative(Native Method)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at java.lang.reflect.Method.invoke(Method.java:507)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at dalvik.system.NativeStart.main(Native Method)
02-27 01:25:19.419: E/AndroidRuntime(5326): Caused by: android.content.ReceiverCallNotAllowedException: IntentReceiver components are not allowed to register to receive intents
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.app.ReceiverRestrictedContext.registerReceiver(ContextImpl.java:151)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.app.ReceiverRestrictedContext.registerReceiver(ContextImpl.java:145)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at com.doublep.wakey.PowerConnectionReceiver.onReceive(PowerConnectionReceiver.java:46)
02-27 01:25:19.419: E/AndroidRuntime(5326):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:1915)
02-27 01:25:19.419: E/AndroidRuntime(5326):     ... 10 more
</code></pre>
