crmepham
crmepham

Reputation: 4740

BroadcastReceiver isn't receiving ACTION_SCREEN_OFF intent

I have created a BroadcastReceiver that should listen for the "ACTION_SCREEN_OFF" intent.

public class ExampleReceiver extends BroadcastReceiver {

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

        // run a service..
    }

}

I have registered it in the Manifest:

<receiver android:name=".path.to.ExampleReceiver">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_SCREEN_OFF"></action>
    </intent-filter>
</receiver>

But when the screen is turned off, the onReceive() method is not called. What else do I need to do to get this functionality?

Upvotes: 3

Views: 308

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006604

ACTION_SCREEN_OFF is not sent to receivers registered in the manifest. It is only sent to receivers registered via registerReceiver() from a running component.

Upvotes: 5

Related Questions