Activity Alarm do not turn on screen in Sony Xperia P when alarm played

做~自己de王妃 提交于 2019-12-13 02:41:55

问题


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());
}

回答1:


Try adding this permission to your AndroidManifest.xml:

<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />


来源:https://stackoverflow.com/questions/25930764/activity-alarm-do-not-turn-on-screen-in-sony-xperia-p-when-alarm-played

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!