我已经安排好闹钟了。使用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();发布于 2012-02-10 12:14:23
试着在锁定状态下唤醒你的设备屏幕。
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();
}
}
}https://stackoverflow.com/questions/9221456
复制相似问题