Search code examples
androidbroadcastreceiverandroid-broadcast

Broadcast Receiver doesn't work on Android Gingerbread


I'm developing an Android application which uses a BroadcastReceiver to do some work while the phone is charging. On my Nexus 5 running Android 4.4.4 KitKat it works as expected, but a friend of mine tested this app on a Samsung Galaxy S running Android 2.3.6 Gingerbread and the app worked fine, but the BroadcastReceiver didn't worked.

My code is as follows:

public class PowerConnectionReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {

        Intent serviceIntent = new Intent(context, MyService.class);
        startWakefulService(context, serviceIntent);
    }
}

And then I declare my BroadcastReceiver on the AndroidManifest:

<receiver
        android:name=".activities.PowerConnectionReceiver"
        android:enabled="true">
        <intent-filter>
            <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
        </intent-filter>
</receiver>

Any ideas?

Thanks in advance.


Solution

  • Have you tried with regular broadcast receiver as demonstrated with the following link: http://developer.android.com/training/monitoring-device-state/battery-monitoring.html