|
发表于 2015-4-27 15:47:50
只看该作者
7#
复制你的代码测试了下,正常。。。- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //setContentView(R.layout.activity_main);
- // 屏蔽系统的屏保
- /*
- KeyguardManager manager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
- KeyguardManager.KeyguardLock lock = manager
- .newKeyguardLock("KeyguardLock");
- lock.disableKeyguard();
- */
-
- // 注册一个监听屏幕开启和关闭的广播
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_SCREEN_ON);
- filter.addAction(Intent.ACTION_SCREEN_OFF);
- registerReceiver(screenReceiver, filter);
- }
- BroadcastReceiver screenReceiver = new BroadcastReceiver() {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (action.equals(Intent.ACTION_SCREEN_ON)) {
- // 屏幕显示
- Log.i("test", "ACTION_SCREEN_ON----->");
- } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {// 接受到关闭屏幕的广播
- // 开启屏幕唤醒,常亮
- // PowerManagerWakeLock.acquire(ScreenSaverS.this);
- //PowerManagerWakeLock.acquire(ScreenSaverS.this);
- //PowerManagerWakeLock.release();
- Log.i("test", "ACTION_SCREEN_OFF----->");
- }
- }
- };
复制代码 |
|