0

iam currently using camera and surfaceview in my app to use Torch etc ... , im using these in an Activity , How to use Camera and SurfaceView in Background , ex . : I want to keep Torch/Led Flash On , i saw many Widget that work fine in Background , how they do it ?

Thanks .

Chalom.E
  • 617
  • 5
  • 20
  • http://stackoverflow.com/questions/6068803/how-turn-on-only-camera-flash-light-programmatically-in-android – DeeV Sep 11 '12 at 15:06
  • Thanks for your answer but this way is not working , im unable to use camera without a SurfaceView , using ICS ... – Chalom.E Sep 11 '12 at 15:12
  • I don't know about ICS specifically, but know I've gotten the camera to work in the background by setting the size of the view to 0 width and 0 height. You need a SurfaceView to attach the camera too, but you can make it invisible. – DeeV Sep 11 '12 at 15:15
  • Yes , but how can i use SurfaceView from Background , Ex : Using a Service , there is no Views ... – Chalom.E Sep 11 '12 at 15:16
  • You said it was a widget which means it's not in the background. It's a forground app on the homescreen. – DeeV Sep 11 '12 at 15:20
  • ok this is a little complicated , this is a widget , when you click it , it start an activity with a Torch Button , im using services to do somes stuff , exepting Camera wich i use from an Activity , now i would like to use Camera/Torch from a service my Apps : https://play.google.com/store/apps/details?id=com.WidName.Widget.Free&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5XaWROYW1lLldpZGdldC5GcmVlIl0. – Chalom.E Sep 11 '12 at 15:22
  • You can't use the camera from a Service. You need a foreground activity of some sort whether it be from the widget or from the activity. http://stackoverflow.com/questions/6901542/android-use-camera-from-within-background-service – DeeV Sep 11 '12 at 15:29
  • sorry about extending the discussion in comments , Thanks you for your answer ... i dont know how to do that ... beacause when i leave or onPause from my Activity , Camera is Released ... – Chalom.E Sep 11 '12 at 15:33

1 Answers1

0

Take a look here:

http://developer.android.com/guide/topics/media/camera.html

There is all the code you need to make an activity which shows the camera preview. As the Camera API:

http://developer.android.com/reference/android/hardware/Camera.html#setPreviewDisplay%28android.view.SurfaceHolder%29

specifies...you need to use a SurfaceHolder for your preview. Thus you can only use a SurfaceView or a derived class for your automatic preview. Otherwise you can use for example a TextureView or an ImageView to draw your preview by yourself. You'll need though to implement the onFramePreview method to grab the frames from the preview and handle them by yourself. By using OpenGL or the ANI API you can also add effects to your frame. This is the only way, I know about, to also add effects directly on your preview, unless these effects can be achieved by overlaying a semi-transparent colored surface above your preview image.

type-a1pha
  • 1,891
  • 13
  • 19