I am using the code provided at the following URL to try using the Android Camera API:
http://marakana.com/forums/android/examples/39.html
This raised several questions, which I tried in vain to find answers so far.
1) My application should be in portrait orientation, but all the code examples that I saw (including the URL above) all seem to depend on the landscape orientation. In fact, no matter what I have tried so far, it seems that the landscape is inevitable. I tried to force the parameters in the surfaceCreated(...)following way:
Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
parameters.set("rotation", "90");
camera.setParameters(parameters);
I tried to do the same in surfaceChanged(...). Of course, I also set my portrait orientation in the manifest as follows:
android:screenOrientation="portrait"
- , , ?
2) , . , , surfaceDestroyed(...) :
camera.stopPreview();
camera = null;
, , , . , , :
camera.stopPreview();
camera.release();
camera = null;
, , , "Force Close" LogCat:
FATAL EXCEPTION: main
java.lang.RuntimeException: Method called after release()
at android.hardware.Camera.setHasPreviewCallback(Native Method)
at android.hardware.Camera.access$600(Camera.java:58)
at android.hardware.Camera.$EventHandler.handleMessage(Camera.java:344)
at android.os.Handler.dispatchMessage(Handler.java.99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lanf.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
- , ?
. .
P.S. HTC Evo.