I am developing a Kotlin android app, when something happens in the app, I want the front-facing camera to record in the background to capture a users reaction for 5 seconds then storing the video in an object to be used in another feature, leaving the apps activity will break it so i am wondering is it possible to do this in the background?
Thanks in advance
You can use foreground services to use the camera in the background.
Foreground services keep running even after the Application is removed by the user from recents screen.
Make sure to read the restrictions applied by Android to these kinds of services:
https://developer.android.com/guide/components/foreground-services#access-restrictions
Related
I'm trying to develop an App which need high security, and user can't take a screenshot or record a video from app, these are a very important features for my app. How do I need to do in a Flutter app to call the native code, or how to prevent these from native code?
On iOS there simply isn't a way to prevent screenshots / capture, you can only detect when a screenshot has already been made (like Snapchat).
On Android you could use the Display flag FLAG_SECURE (more about that here: https://developer.android.com/reference/android/view/Display.html#FLAG_SECURE).
Mind that this won't prevent all possibilities of screen capture as #Markus Kaupinnen pointed out in the comments of the question.
I am developing an Android security app, and I want to capture images in background without preview. Is it possible to capture images in the background using the camera2 api?
Yes, but as of Android 5.0 Marshmallow, you may be disconnected from the camera at any time, if a foreground app wants to use it instead.
And before Android M, using the camera from the background is not recommended, since you'll block any foreground app from using it (the app will just get an error trying to open the camera, and generally will crash as a result).
Otherwise, the camera API works the same. You'll need to run the camera for a few seconds before taking the final picture to ensure metering and focus are generally good, though exactly what you need would depend highly on the details of your use case.
I have doing a basic object detection on the camera preview screen in Android (greater than 3.2). For the devices which do not support processing on preview screen, I am buffering the preview screen, processing it and clearing the buffer. This part is working as desired.
What I now want is this app to run in the background while any other app is running in the foreground. I am using android service and am able to run a small test app in the background. However my concern is with the camera preview app.
I don't want to display the preview screen but use the preview screen information for processing. This might be too much to ask, but I wanted to know if this is even possible. I came across this link which shows some hope. Basically I want to process the video (preview) stream without displaying it on the screen. If this is doable, then I can think of putting this app in the background and some other app in the foreground.
Unfortunately I won't be able to share the code, however it is the standard logic of creating a surface view and starting the preview.
I would really appreciate any insight into this.
Check comments here.Basically he opens camera hardware, set preview callback and do startpreview without setting the previewDisplay (this might not work on every device). You can try this from your background service. All this will work if your foreground doesn't access the camera app. Please update this if it works. I am interested to know.
I am developing an application to take images from background application say using android service. i don't want any user interaction to takes images, it should completely work from background.
I have already tried -
Calling camera from service - It not always works sometime works if we have dummy surfaceview, again if Android close the related activity service stopped takings pics, I don't want to run activity for user interaction.
with some changes it working fine but all images are black.
Widget: Not getting how to call camera in widget as widget doesn't support surfaceview.
Live wallpaper: not able to make it work till now, does it supports for camera?
As per my experience till now Android camera service not designed to takes picture if no real preview available.
Is anyone developed something like this? any help will be really appreciate.
If you can ignore older versions, it may be easier to use SurfaceTexture (API 11 and higher) As vikky.rk notes in an answer to a recent question, an introduction to this technique can be found in the PanoramaActivity code of the default Android Camera App.
I'm trying to figure out if it is possible to use a camera video stream from within a background service rather than from a normal intent.
What I had in mind is this:
start the service from my app
this service accesses the video stream and extracts features continuously; depending on the features, it sends network packets (to localhost)
user switches to another app - the service must still be running and extracting features!
Before trying to implement all that, I'd like to know if it was possible.
Thanks in advance
Nicola
yes its possible, check my answer and sample code on one similar thread
Open/Run Camera from background service in android
You have to show the fake preview over the current screen. For that you have to create the surface view with 1*1 px dimension and display the preview in that. You have to draw the surface view over other apps for that.
Check out this library that provides facility to capture image from the background even from the service.
I don't think this is possible as the camera needs a preview screen. See previous question here