BroadcastReceiver for Screen On/Off not working

后端 未结 3 1394
夕颜
夕颜 2020-12-05 21:43

I am trying to use BroadcastReceiver but it is not working, please help me to solve this problem. MyReceiver.java

package com.example.broadcast_receiver;

im         


        
3条回答
  •  猫巷女王i
    2020-12-05 22:00

    If you want this receiver to be called by the system, you would need to export it. You set exported = "false", change this to true or remove exported entirely and this will start working. Normally this would be insecure, but as both SCREEN_ON and SCREEN_OFF are protected-broadcasts, and you verify the actions, only more trusted system code can send them too you, so it's pretty safe.

    Sadly this wont work in this case as the intents broadcast have the following flags: Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND

提交回复
热议问题