1

Would it be possible to listen for events while the phone/screen is locked. Like for example, to record sounds and process that in the background?

Thanks,

user1174960
  • 83
  • 3
  • 9

1 Answers1

0

Running service are down when the phone is locked, but you can acquire WAKE_LOCK key and do your task

PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 
                                    "MyWakeLock"); 
wakeLock.acquire();

this will hold the CPU open even if the screen off, then you can do your process in background

https://stackoverflow.com/a/6091362/1025070

Community
  • 1
  • 1
UdayaLakmal
  • 4,035
  • 4
  • 29
  • 40