首页 > 解决方案 > Why does this static Receiver not respond to the ACTION_POWER_(DIS)CONNECTED Event?

问题描述

I want a STATIC Broadcast Receiver to get fired, whenever the Phone gets charged or not. In my Manifest.xml, i have written the following Entry:

<receiver
    android:name=".Starter">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
        <action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
    </intent-filter>
</receiver>

The Broadcast Receiver itself looks like this:

public class Starter extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "blablabla", Toast.LENGTH_LONG).show();
    }
}

When I register the Receiver programmatically, everything works fine, but I want the Receiver also to respond, when the Activity is not open, so I have to make a static Receiver. Thank you for your help!!!

标签: staticbroadcastreceiver

解决方案


推荐阅读