我创建了一个应该监听“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>
方法。我还需要做些什么才能获得此功能?
答案 0 :(得分:4)
ACTION_SCREEN_OFF
不会发送到清单中注册的接收者。它仅发送给通过registerReceiver()
从正在运行的组件注册的接收者。