How to wake up an android and show activity?

Please help me. I have a broadcast receiver:

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 works, my android does not wake up: the button blinks once, and that’s all. Where is the mistake?

I want to wake up android and cause some activity as a result. Thank.

+5
source share
2 answers

In the Office you want to show, you can add these flags:

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

This will make Activity wake up the device.

+14
source

It is worth noting that what “joelreeves” writes even works without using the PowerManager and Wakelock APIs. By simply adding flags to onCreate activity, whenever it starts, it will completely remove Keyguard and Lock from the phone.

+2