Почему в эмуляторе отслеживается разблокировка экрана а в смартфоне нет

В Android приложении мне нужно отследить когда экран телефона на определенной активности заблокировался и разблокировался для того чтобы воспроизвести видео в активности заново. Внизу часть кода которая это отслеживает, в эмуляторе все работает верно, но на реальном устройстве отслеживается только блокировка экрана, а при разблокировки ничего не происходит, проверяла на двух устройствах.

   @Override
protected void onPause() {
    // when the screen is about to turn off
    if (ScreenReceiver.wasScreenOn) {

        // this is the case when onPause() is called by the system due to a screen state change
        Log.e("MYAPP", "SCREEN TURNED OFF");
    } else {
        // this is when onPause() is called when the screen state has not changed
    }
    super.onPause();
}

@Override
protected void onResume() {
    super.onResume();
    // only when screen turns on
    if (!ScreenReceiver.wasScreenOn) {

        finish();
        overridePendingTransition(0, 0);
        startActivity(getIntent());
        overridePendingTransition(0, 0);

        // this is when onResume() is called due to a screen state change
        Log.e("MYAPP", "SCREEN TURNED ON");
    } else {
        // this is when onResume() is called when the screen state has not changed
    }
}

@Override
protected void onDestroy() {
    if (mReceiver != null) {
        unregisterReceiver(mReceiver);
        mReceiver = null;
    }
    super.onDestroy();
}

Ответы (0 шт):