Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Several Camera API Questions
    primarykey
    data
    text
    <p>I am using the code provided at the following URL to try to work with the Android Camera API:</p> <p><a href="http://marakana.com/forums/android/examples/39.html" rel="nofollow">http://marakana.com/forums/android/examples/39.html</a></p> <p>This has raised several questions that I have tried in vain to find the answers to so far.</p> <p>1) My application needs to be in portrait orientation, but all the code examples I have seen (included that at the URL mentioned above) all seem to depend on landscape orientation. In fact, no matter what I have tried so far, it seems that landscape is inescapable. I have tried forcing the parameters in <code>surfaceCreated(...)</code> like so:</p> <pre><code>Camera.Parameters parameters = camera.getParameters(); parameters.set("orientation", "portrait"); parameters.set("rotation", "90"); camera.setParameters(parameters); </code></pre> <p>I have tried doing the same thing in <code>surfaceChanged(...)</code>. Of course, I am also setting my orientation to portrait in the manifest as follows:</p> <pre><code>android:screenOrientation="portrait" </code></pre> <p>Does anyone have any suggestions on what I'm doing wrong and how to fix it?</p> <p>2) Another question I have has to do with releasing the camera resources. In the code from the article referenced above, the following are called in the <code>surfaceDestroyed(...)</code> method:</p> <pre><code>camera.stopPreview(); camera = null; </code></pre> <p>There is nothing to release the camera resources, so after you have run this application, any subsequent application that uses the camera will not work. In am attempt to fix this, I added a call to release the resources, like this:</p> <pre><code>camera.stopPreview(); camera.release(); camera = null; </code></pre> <p>The problem there, though, is that when I close the application, I get a "Force Close" with the following exception in LogCat:</p> <pre><code>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) </code></pre> <p>Can anyone tell me why I can't release the camera resources there?</p> <p>Thank you all in advance. This camera thing is driving me nuts.</p> <p>P.S. I am testing all of this on an HTC Evo.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload