0

I have Android 7 (API 24). I launch my app which launches started service. Then timeout causes screen to turn off. The service does something in background and eventually wants to turn the screen back on. How can I turn the screen on from service?

I already tried:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "MyApp::MyWakelockTag");
wl.acquire();

The permission for WAKE_LOCK was set. I also wanted to use FULL_WAKE_LOCK flag, but this is deprecated. Anyway, this doesn't work.

I also tried to launch my activity from service and implement this in OnResume of my activity:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

This also doesn't work (i.e. it doesn't turn the screen on).

Thank you for your help.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Martin Dusek
  • 1,170
  • 3
  • 16
  • 41
  • Check this one https://stackoverflow.com/questions/30246425/turning-on-screen-from-receiver-service/30365638 – Ravindra Bagale Nov 12 '19 at 19:47
  • Caa you please post actual code that should work on my device? I tried window.addFlags with various flags in onCreate, onStart, onResume methods of my activity (which is started from my service when an event occurs). I also tried wake lock acquire in my service. Nothing works. – Martin Dusek Nov 12 '19 at 20:00
  • Are you calling `Activity.finish()` at any point? – greeble31 Nov 12 '19 at 20:35
  • No, finish() is never called – Martin Dusek Nov 12 '19 at 21:09
  • `addFlags(FLAG_TURN_SCREEN_ON|FLAG_KEEP_SCREEN_ON)` in your `Activity.onCreate()` should've worked. You don't actually need a `WakeLock` to ensure the screen turns on, as long as you can guarantee `Activity.onCreate()` is executing. – greeble31 Nov 13 '19 at 01:58

0 Answers0