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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.