BroadcastReceiver没有收到ACTION_SCREEN_OFF意图

时间:2016-02-21 14:27:54

标签: java android android-intent broadcastreceiver

我创建了一个应该监听“ACTION_SCREEN_OFF”意图的protocol ViewEvent { func viewWillAppear(animated: Bool) func viewDidAppear(animated: Bool) func viewWillDisappear(animated: Bool) func viewDidDisappear(animated: Bool) } extension UIViewController: ViewEvent {} typealias FooController = protocol<UIResponder, ViewEvent, Foo>

BroadcastReceiver

我已在Manifest中注册了它:

public class ExampleReceiver extends BroadcastReceiver {

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

        // run a service..
    }

}

但是当屏幕关闭时,不会调用<receiver android:name=".path.to.ExampleReceiver"> <intent-filter> <action android:name="android.intent.action.ACTION_SCREEN_OFF"></action> </intent-filter> </receiver> 方法。我还需要做些什么才能获得此功能?

1 个答案:

答案 0 :(得分:4)

ACTION_SCREEN_OFF不会发送到清单中注册的接收者。它仅发送给通过registerReceiver()从正在运行的组件注册的接收者。