Capturing image when in background/locked?

1,131 views
Skip to first unread message

henri.s...@iki.fi

unread,
Jul 10, 2020, 1:52:55 AM7/10/20
to Android CameraX Discussion Group
Hi,

I'm making an enterprise app that has a requirement to be able to capture images from the phone camera when its locked. The traditional way has been to use an external camera, but we want to try to save cost and leverage the device internal camera.

Is this possible with CameraX? I've seen some examples for earlier APIs, but I haven't been able to figure out if this is doable with CameraX.

Br,
//HS

Vinit Modi

unread,
Jul 10, 2020, 10:21:56 AM7/10/20
to henri.s...@iki.fi, Android CameraX Discussion Group
Hi HS,

Thanks for trying CameraX. Per your title, taking a picture with the app in the background is no longer allowed per the Android framework and CameraX honors those same rules.

How do you intend to trigger the app while the phone is locked? Will it be triggered by the power button, script, etc.? Is the application being used in an industrial environment or by an enterprise user? Some more information here will help us to provide an answer. Thanks!

Vinit

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/6e9d1742-92c3-435a-90aa-a2aef35735bfo%40android.com.

henri.s...@iki.fi

unread,
Jul 10, 2020, 10:46:48 AM7/10/20
to Android CameraX Discussion Group, henri.s...@iki.fi
Hi,

Yes, I've been following the recent trend on those permissions. We are however still on Android 6 and 7, for at least a few years. The sector we work with uses often very custom & ruggerized devices, and I guess I can say that many customers are in the public sector.

Camera can be triggered by a central command room operator via network at will, there may not be any user interaction. There might be also AI-based rules that will trigger the camera to take images, or maybe record video automatically. The user may also trigger the camera, but that is just a normal photo taking use case.

Vinit Modi

unread,
Jul 14, 2020, 6:07:23 PM7/14/20
to henri.s...@iki.fi, Android CameraX Discussion Group
Hi Henri,

Following up on this discussion and including feedback from the wider team
  • You can do this without a lot of trouble by having a foreground service for your app (Think music player, navigation, type active notification). It'll be preempted by other camera apps if they're launched or running when the service attempts to open the camera, but it does work (The service doesn't actually need to do anything other than just be launched and active for the duration the camera is in use, but it will be very visible to the user). The restrictions are designed to avoid *silent* opening of the camera, but having an active foreground notification is sufficient.
  • If you tie CameraX to a foreground service lifecycle, it should possibly just work (with only an Analysis / ImageCapture use cases, Preview obviously won't work).
    That'll display a notification, which is the right thing from a user notification perspective, and should continue to work with screen off.  
  • If you don't want a foreground service, then you need to create their own lifecycle object to drive CameraX with
    • Note that this assumes you are targeting Android 6 and 7 as you mentioned earlier
Hope this helps, thanks! 
Vinit

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

henri.s...@iki.fi

unread,
Jul 28, 2020, 7:55:26 PM7/28/20
to Android CameraX Discussion Group, henri.s...@iki.fi
Hi Vinit!

Thanks for such a comprehensive reply! I think for this project, the custom lifecycle is the correct way to go. We'll tackle newer Android versions when appropriate - we do have many years at the moment to make future plans.

Any good pointers for such a custom lifecycle - Its definitely something we haven't done before...

Br,
//HS

Scott Nien

unread,
Jul 28, 2020, 10:26:16 PM7/28/20
to henri.s...@iki.fi, Android CameraX Discussion Group

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.

henri.s...@iki.fi

unread,
Aug 27, 2020, 12:34:34 PM8/27/20
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, henri.s...@iki.fi
Hi, I finally got the time to test this, and yes it does indeed keep working after you press a button to lock the phone.

However it seems that in some point something else happens, like more secure locking/power saving, and it eventually stops working. Any ideas to mend that?

Scott Nien

unread,
Aug 28, 2020, 12:24:57 PM8/28/20
to henri.s...@iki.fi, Android CameraX Discussion Group
Can you have the logs to check what was going on ?  

I think anything could happen to stop the camera..  maybe OEM tried to kill all the foreground services to save power. It is just difficult to know what went wrong without the logs. 
Reply all
Reply to author
Forward
0 new messages