播放警报时,活动警报不会在Sony Xperia P中打开屏幕

时间:2014-09-19 09:33:23

标签: java android keyguard keyguardlock

Android上的我的闹钟程序在许多三星和HTC设备上都不起作用;在手动打开屏幕之前,它不会打开屏幕并且不会播放警报。 这个问题出在索尼Xperia P和华为Honor手机上...... 我使用任何我认为在我的代码中解决我的问题的东西,但它没有修复! :(

这是我的代码:

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 个答案:

答案 0 :(得分:0)

尝试将此权限添加到AndroidManifest.xml

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