0

I am stuck into a problem programming an android application, using Java. I am implementing a Service, since my application should run in background, without affecting the other functionalities of the device.

I should access to camera device, I just need to grub the current camera frame within a given framerate. I am a bit confused, since it seems that I cannot access to camera without a view panel (and, since I am programming a service, I don't have a view panel).

I have tried different solutions found online, but no one of them works. I am using Andoird 6.0 (sdk 23). Do you have any hints?

------------ EDIT ------------------

Why should a service access to the camera?

I am working on a robotic system that is interfaced via a set of android API (the robot is composed of 2-layers. One is a standard computer that is not accessible, the other is the android layer with its API). Along with the APIs, the tablet has also different sensors, like a standard tablet camera.

I am developing an interface to get its sensors and make available the APIs via network, enabling the robot to be controlled without writing proper android applications on the robot. I have quite finished, and everything runs in a service, so the user will not lose the control of the robot tablet. However, I am not able to stream the camera data.

Regards,

3
  • Why a service should access the camera? Please describe your use case from end user point of view. Commented Mar 14 at 20:21
  • Thanks, I added further info to my problem. Commented Mar 15 at 7:35
  • I suggest to use only ImageCapture and start the camera using following statement: Camera camera = cameraProvider.bindToLifecycle(this, cameraSelector, imageCapture); Commented Mar 15 at 18:32

1 Answer 1

0

Your approach seems to be technically infeasable. Unfortunately (because of security concerns) Android does not allow you to send a camera feed without a foreground application (You would be able to spy on people).

To make things easier, you could have a workaround that would make your setup significantly easier. Because you are using a Tablet you could start your App in a Splitscreen with the Robot App. People couldbe able to view your App (and you could display Robot Data) and you would be able to capture and send Camera Data. You could look here for a way of implementing the splitscreen!

Sign up to request clarification or add additional context in comments.

3 Comments

This answer is wrong. The Android OS is based on the user granted permissions where security concerns are applicable, like for the camera where the user has to grant explicit permission. Once permission is granted by the user, the application can launch service to capture images and do video streaming like DroidCam does.
Even though Jonathan asked for a solution running from API 23 there are restrictions in ongoing API Levels. There cannot be a viable solution circumventing Android security policies. developer.android.com/develop/background-work/services/fgs/… EDIT: Also DroidCam uses a Foreground Service which Jonathan definitely didn't want to use. It only works beacuse the App is started and visible or on age-old and potentially harmfully insecure API Levels
A foreground service fits the usecase described by OP far better that a splitted screen solution, as foreground services continue running even when the user isn't interacting with the app. Note that DroidCam works well on my device running API 34 after giving proper permission without any further user interaction, and it does not need to be visible any more, once permission is given.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.