Android: ACTION_POWER_CONNECTED event not sent to my BroadcastReceiver

I want to do something after the phone is in the charger. So I created ChargingOnReciever :

 public class ChargingOnReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { context.startActivity(someActivity); Log.d(TAG, "Phone was connected to power"); } } 

and I want my receiver to listen for android.intent.action.ACTION_POWER_CONNECTED , so I injected this into the manifest:

 <reciever android:name=".ChargingOnReceiver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.ACTION_POWER_CONNECTED" /> </intent-filter> </reciever> 

But ChargingOnReceiver does not seem to start when I install my G1 in the charger (connect to the laptop via the USB cable). Any help is much appreciated.

+7
android android-intent
source share
3 answers

This is the receiver, not the receiver! It took me 5 hours to find this stupid mistake. I think the Android Eclipse plugin should do some syntax checking in the xml manifest.

+25
source share
  • Do not start the action with BroadcastReceiver .

  • Did you check LogCat while plugging in the USB cable to find out if there are any logged messages that might explain your problem?

0
source share

In the documentation write android.intent.action.POWER_CONNECTED without ACTION_ .

-one
source share

All Articles