My alarm program on Android does not work on many Samsung and HTC devices; it does not turn on the screen and does not play alarm until the screen is manually turned on. This problem is in Sony Xperia P and Huawei Honor phone... I use any thing that I think solve my problem in my code, but it isn't fixed! :(
This is my code:
try {
// baraye roshan kardane safe va roshan negah dashtane oon dar Huawei honor
PowerManager mPowerManager = (PowerManager) PlayAlarmActivity.this.getSystemService(Context.POWER_SERVICE);
mWakeLock = mPowerManager.newWakeLock((PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP), "Power Manager");
mWakeLock.acquire();
Log.i("Unlock Screen", "1");
} catch (Exception e) {
Log.e("Error in playalarmactivity for unlock screen 1 ...", e.toString());
}
try {
// Set the window to keep screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
Log.i("Unlock Screen", "2");
} catch (Exception e) {
Log.e("Error in playalarmactivity for unlock screen 2 ...", e.toString());
}
try {
// baraye baz kardane lock dar gooshihayi mesle sonye Masoud!!! :D
km = (KeyguardManager) PlayAlarmActivity.this.getSystemService(Context.KEYGUARD_SERVICE);
kl = km.newKeyguardLock("MyKeyguardLock");
kl.disableKeyguard();
Log.i("Unlock Screen", "3");
} catch (Exception e) {
Log.e("Error in playalarmactivity for unlock screen 3 ...", e.toString());
}