How to wake up android and show the activity?
Asked Answered
I

2

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.

Illegal answered 7/4, 2013 at 11:54 Comment(0)
V
15

In the Activity that you want to show can you 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);

That will cause the Activity to wake the device.

Vocation answered 18/4, 2013 at 6:52 Comment(0)
S
2

It is worth noting that what "joelreeves" wrote works even without using the PowerManager and Wakelock APIs. By simply adding the Flags on the onCreate of the activity, whenever it starts, it will fully remove the Keyguard and Lock from the phone.

Sempiternal answered 3/7, 2015 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.