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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With