protected void onPause() { super.onPause(); mp.stop(); mp.reset(); PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); boolean isScreenOn = powerManager.isScreenOn(); if (!isScreenOn) { PowerManager.WakeLock wakeLock = powerManager.newWakeLock( PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "TEST"); wakeLock.acquire(); surfaceCreated(holder); } }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(Intent.ACTION_POWER_CONNECTED)) { LOGGER.debug("Power connected, increasing location frequency update."); setOnScreeState(); mPowerConnected = true; } else if (action.equals(Intent.ACTION_POWER_DISCONNECTED)) { LOGGER.debug("Power disconnected, restoring location frequency update."); mPowerConnected = false; PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // if we received a power disconnected event and the screen is off then // set the location update frequency to off screen if (!pm.isScreenOn()) { setOffScreenState(); } } }