我预定了闹钟。使用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 :(得分: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();
}
}
}