我tryng時使用此代碼的景觀時開啓人像proximitywakelock和關閉,但它始終保持活躍:如何關閉wakelock?
//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();
}
}
看起來它從未舉行的風景時... 如何isHeld()
實際工作? 代碼有什麼問題?
這聽起來像你需要在清單文件上聲明wakelock的東西 – jap1968 2012-02-17 13:05:41
已經有 –
2012-02-17 13:06:49