I'm tryng to turn proximitywakelock on when portrait and off when landscape using this code, but it always stays active:
//in onCreate() of my Activity
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
mProximityWakeLock = pm.newWakeLock(32, ""); // proximity_wake_lock=32
mProximityWakeLock.setReferenceCounted(false);
if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "non landascape", Toast.LENGTH_SHORT).show();
if (!mProximityWakeLock.isHeld()) {
mProximityWakeLock.acquire();
Toast.makeText(this, "acquired", Toast.LENGTH_SHORT).show();
}
if (!mProximityWakeLock.isHeld())
Toast.makeText(this, "not held", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, " held", Toast.LENGTH_SHORT).show();
} else {
if (!mProximityWakeLock.isHeld())
Toast.makeText(this, "not held", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, " held", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "landascape", Toast.LENGTH_SHORT).show();
if (mProximityWakeLock.isHeld()) {
mProximityWakeLock.release();
Toast.makeText(this, "released", Toast.LENGTH_SHORT).show();
}
}
It looks like it's never held when on landscape...
How does isHeld()
actually works?
What's the problem with the code?