IF AN EXPERT SAYS IT CAN'T BE DONE GET ANOTHER EXPERT.
As part of my upcoming post about writing an Android portrait camera app I have decided to post few pre posts that might be important to understand.
This post, and related ones such as Android Development and Threads might be relevant for some readers and I strongly suggest going over them in case you are not sure about these topics.
From Android documentation for the Camera API:
To access the device camera, you must declare the CAMERA permission in your Android Manifest. Also be sure to include the
manifest element to declare camera features used by your application. For example, if you use the camera and auto-focus feature, your Manifest should include the following
<uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" />
This class was deprecated in API level 21. Android's recommendation is to use
I am not gonna talk about the Camera2 API in this post, but might do that in another one later on.
onCreateas it might slow down the UI thread - this raises an interesting question when the UI is dependent on the camera preview size, I will cover this topic in my future post writing an Android portrait camera app.
onResumein order to open the camera.
Your application should only have one Camera object active at a time for a particular hardware camera.
camera.release()but the following:
From Android's documentation:
Use the Camera.takePicture() method to take a picture once the preview is started. You can create Camera.PictureCallback and Camera.ShutterCallback objects and pass them into Camera.takePicture().
If you want to grab images continously, you can create a Camera.PreviewCallback that implements onPreviewFrame(). For something in between, you can capture only selected preview frames, or set up a delayed action to call takePicture().
As mentioned above, this is a very basic post about how to work with Android's camera. Everything above is mentioned in Android's documentation, most of it can be found in Android's page Controlling the Camera and in the Camera Documentation