5

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

Nicola Montecchio
  • 477
  • 1
  • 7
  • 18

3 Answers3

3

yes its possible, check my answer and sample code on one similar thread

Open/Run Camera from background service in android

Community
  • 1
  • 1
Pawan Maheshwari
  • 15,088
  • 1
  • 48
  • 50
  • 1
    your method is working ONLY if you open activity firstly - to initialize surfaceview, then use it in service – Choletski Aug 24 '17 at 14:56
1

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.

Keval Patel
  • 592
  • 3
  • 13
  • While Trying to use this library i am getting Camera error. Unable to open camera or something. Please suggest what should i do. – Vipin NU Feb 26 '19 at 07:09
-4

I don't think this is possible as the camera needs a preview screen. See previous question here

Community
  • 1
  • 1
John J Smith
  • 11,435
  • 9
  • 53
  • 72