2012-02-10 149 views
2

我安排了闹钟。使用WakeLock.acquire()KeyguardLock.disableKeyguard(),我可以唤醒屏幕并显示我的活动。不过,我宁愿只显示一个对话框。我的HTC和三星设备内置报警器就是这样做的。我期望在KeyguardLock对象上找到一种方法,但是我没有看到任何让我朝这个方向发展的文档。我怎样才能保持KeyguardLock,但显示我的对话框内置报警的方式。这是我在onCreate()唤醒屏幕并在锁定屏幕上显示对话框

KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); 
    keyguardLock = km.newKeyguardLock(KeyguardLockTag); 
    keyguardLock.disableKeyguard(); 

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
    int flags = PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP; 
    wakeLock = pm.newWakeLock(flags, WakeLockTag); 
    wakeLock.acquire(); 
+0

您是否找到了解决方案? – Behzad 2013-02-22 23:37:26

+0

@Behzad我没有按照描述完成,但现在回顾(此线程已超过一年),您可以将对话样式设置为对话以获得相同的结果。如果你不熟悉如何做到这一点,谷歌“Android风格的活动作为对话”。这很容易在清单中的Activity元素中完成。 – Rich 2013-02-22 23:51:06

+0

是的,你是对的。谢谢。 – Behzad 2013-02-23 00:23:05

回答

0

运行刚刚尝试这一点,即使在锁来唤醒您的设备屏幕当前的代码。

package android.taskscheduler; 

import android.app.IntentService; 
import android.content.Context; 
import android.content.Intent; 
import android.os.PowerManager; 

public abstract class WakeIntentService extends IntentService 
{ 
abstract void doReminderWork(Intent intent); 
public static final String LOCK_NAME_STATIC = "your_package_name"; 
private static PowerManager.WakeLock lockStatic = null; 

public static void acquireStaticLock(Context context){ 
    getLock(context).acquire(); 
} 

synchronized private static PowerManager.WakeLock getLock(Context context) 
{ 
    if(lockStatic == null) 
     { 
      PowerManager powManager = (PowerManager)  context.getSystemService(Context.POWER_SERVICE); 

    lockStatic = powManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, LOCK_NAME_STATIC); 
    lockStatic.setReferenceCounted(true); 
    } 
    return (lockStatic); 
} 
public WakeIntentService(String name) 
{ 
    super(name); 
} 
@Override 
     final protected void onHandleIntent(Intent intent) 
{ 
     try{ 
      doReminderWork(intent); 

     }finally 
    { 
     getLock(this).release(); 

     } 
    } 
}