我安排了闹钟。使用 WakeLock.acquire()
和 KeyguardLock.disableKeyguard()
,我能够唤醒屏幕并显示我的 Activity 。但是,我更愿意只显示一个对话框。我的 HTC 和 Samsung 设备上的内置闹钟就是这样工作的。我希望在 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();
最佳答案
试试这个,即使在锁定时也能唤醒您的设备屏幕。
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();
}
}
}
关于android - 唤醒屏幕并在锁定屏幕上显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9221456/