0

I'm developing a motion detection app. This app uses the camera to compare continuosly taken frames to detect movement. So, I need the app to stay working and not being paused or stoped. I'm using WakeLock to achieve this, but I'm seeing in the android doc, that most methods are deprecated.

I don't care if the screen goes off, but the app must keep working. Now I'm using this:

mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "APP");

But the app stops when the screen goes off. I've seen that maybe this one fits better my porpouse: SCREEN_DIM_WAKE_LOCK but was deprecated in API level 17...

So, what would be the best way to get this?

masmic
  • 3,526
  • 11
  • 52
  • 105
  • Have a look at the folowing post, that suggests using a service. A service might be a good choice for your type of task because its able to keep working while the screen is black / your app is idle. http://stackoverflow.com/questions/19283529/how-to-use-android-camera-in-background – alex May 13 '14 at 08:01
  • Have you given the permission in the manifest file? Check the documentation - http://developer.android.com/training/scheduling/wakelock.html – Ramesh Prasad May 13 '14 at 08:09
  • @alex I think maybe is the best way to do it that way, but I'll make the change in the next app update. Now I just need the app for some work tests, and I haven't got time to start changing things – masmic May 13 '14 at 08:10
  • @Ramesh Prasad Yes I do. I've done some test and it works now in the device I'm using with `SCREEN_DIM_WAKE_LOCK`, I get the functionality i need, but I don't know if it will work in a kitkat device – masmic May 13 '14 at 08:12
  • I suggest you use PARTIAL_WAKE_LOCK. If thats not working then as mentioned in doc, use FLAG_KEEP_SCREEN_ON - http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_KEEP_SCREEN_ON – Ramesh Prasad May 13 '14 at 08:27

1 Answers1

0

Best solution is to keep screen on.

Add android:keepScreenOn="true" in your layout XML resource for this activity. So long as that widget is visible on the screen, the screen will not turn off automatically.

Also use the permission:

<uses-permission android:name="android.permission.WAKE_LOCK" />