Android Camera Application, preview crash
So I started with this little write-up. I wanted to try to make an application that will take pictures while running in the background. To start though I wanted an application that once opened would simply take a picture every X seconds. After recreating the classes and methods show in the walk through below I ran into a few problems.
http://itp.nyu.edu/~sve204/mobilemedia_spring10/androidCamera101.pdf
For starters its seems that the onCreate function sets up all the objects for the application, but if you try to take a picture through any other method than onClick (IE directly calling it) the application actually hasn't setup the canvas or the preview yet.
My first question: Is there any conditional method that you can setup that will wait till all the "onCreate" objects are created and their associated methods are called and finished? How do I wait for the appli开发者_如何学运维cation to finish putting together my surface and starting the cameras preview before automatically starting to take pictures?
My second question: I am required to have a preview available to take pictures. Is there anyway to push this application to the back (IE running in the background) while still taking pictures? Is drawing to a canvas a requirement? (From what I can tell AFAIK, you are required to have a surfaceholder to start preview, when you put up another screen or application that pauses the current application and closes the surface/canvas you were presenting that preview on). If my understanding is correct on all of this the best I will be able to do is make a 1x1 pixel canvas that will still take up the screen due to the application being in the foreground.
My Third question: is there any way around this? Can you still utilize the camera in some fashion without requiring the preview be drawn?
You have to implement
SurfaceHolder.Callback
and wait for it'ssurfaceCreated()
to be called.After that you can do all
MediaRecorder
preparation (setPreviewDisplay,setAudio, setVideo, prepare()).You can overlay SurfaceView with another view and thus hide it.
精彩评论