Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After days of trying and further reading I found out that it was a timing problem. The Camera object is released before the jpeg callback is called. You just have to release the camera inside the callback.</p> <pre><code>package com.brushmate.chameleon; import java.io.IOException; import android.graphics.SurfaceTexture; import android.hardware.Camera; import android.os.Bundle; import android.os.SystemClock; import android.annotation.SuppressLint; import android.app.Activity; import android.util.Log; import android.view.SurfaceView; public class SettingsActivity extends Activity { private static final String TAG = "Chameleon Wallpaper"; @SuppressLint("NewApi") protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); Log.d(TAG, "Activity created"); Camera cam = getCamera(); if (cam != null) { Log.d(TAG, "Camera available"); SurfaceTexture dummy = new SurfaceTexture(0); try { cam.setPreviewTexture(dummy); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d(TAG, "Preview texture set"); cam.startPreview(); Log.d(TAG, "Preview started"); cam.takePicture(null, null, new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) { Log.d(TAG, "Image taken"); cam.stopPreview(); Log.d(TAG, "Preview stopped"); cam.release(); Log.d(TAG, "Camera released"); } }); } } private Camera getCamera() { Camera cam = null; try { cam = Camera.open(); } catch (RuntimeException e) { Log.e(TAG, "Camera not available", e); } return cam; } } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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