5

Please, help me. I have a broadcast reciever:

public class BrcRec extends BroadcastReceiver{
public static WakeLock wakeLock;
@Override
public void onReceive(Context context, Intent intent) {


    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
    wakeLock.acquire();
    //Осуществляем блокировку
    KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); 
    KeyguardLock keyguardLock =  keyguardManager.newKeyguardLock("TAG");
    keyguardLock.disableKeyguard();


    //Здесь можно делать обработку.
    Bundle extras = intent.getExtras();
    StringBuilder msgStr = new StringBuilder();

    msgStr.append("Одноразовый будильник: ");
    Format formatter = new SimpleDateFormat("hh:mm:ss a");
    msgStr.append(formatter.format(new Date()));
    // Creating activity must be there, i think
    Toast.makeText(context, msgStr, Toast.LENGTH_LONG).show();
    //Разблокируем поток.
    wakeLock.release();
}

And then it is in work, my android do not wake up: button blink one time and that is all. Where is a mistake?

I want to wake up android and call some activity in result.. Thank you.

4

2 回答 2

15

在您要显示的活动中,您可以添加这些标志:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
                WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

这将导致 Activity 唤醒设备。

于 2013-04-18T06:52:19.253 回答
2

值得注意的是,“joelreeves”所写的内容即使不使用 PowerManager 和 Wakelock API 也能正常工作。只需在活动的 onCreate 上添加标志,无论何时启动,它都会从手机中完全删除 Keyguard 和 Lock。

于 2015-07-03T13:45:09.513 回答