我想做一个BroadcastReceiver
,以便在屏幕关闭时收到通知,然后我再次打开它,但它什么也没做,有什么问题?
public class SplashScreen extends SherlockActivity {
PowerManager.WakeLock mWakeLock;
BroadcastReceiver rec = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
WakeLock screenLock = ((PowerManager) getSystemService(POWER_SERVICE))
.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
screenLock.acquire();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.sensounlock.R.layout.rotation);
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(rec, filter);
}