2

我有一个闹钟。使用WakeLock.acquire()and 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();
4

1 回答 1

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

       }
   }
}
于 2012-02-10T04:14:23.387 回答