1

I'm trying to make a screen where the use will be able to take a photo. This photo will go to the database. The problem is, I've tried multiple approaches and in every approach, I need to use the PictureCallback. But the onPictureMethod from PictureCallback is never called, no matter what.

I already tried looking into this and this, but still can't move.

Edit: Using Android 2.2 (API 8)

EDITED CODE:

package touchcare.idealogix.android;

//imports

public class CameraActivityTest extends Activity implements SurfaceHolder.Callback
{
private SurfaceView surfaceCamera;
private SurfaceHolder holderCamera;
private Camera camera;
private Button btnCapture;
private PictureCallback mPictureJpg;
private PictureCallback mPictureRaw;
private ShutterCallback shutterCallback;

@Override public void onCreate(Bundle bundle){
    super.onCreate(bundle);
    setContentView(R.layout.layout_camera);

    Log.d("PICTURE", "ACTIVITY START");

    surfaceCamera = (SurfaceView) findViewById(R.id.surfaceCamera);
    btnCapture = (Button) findViewById(R.id.btnCapture);
    holderCamera =  surfaceCamera.getHolder();

    holderCamera.addCallback(this);
    holderCamera.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    shutterCallback = new ShutterCallback() 
    {   
        @Override
        public void onShutter() 
        {
            //DONOTHING
        }
    };

    mPictureRaw = new PictureCallback() 
    {   
        @Override
        public void onPictureTaken(byte[] data, Camera camera)
        {
            //DONOTHING
        }
    };

    mPictureJpg = new PictureCallback()
    {
        @Override
        public void onPictureTaken(byte[] data, Camera camera) 
        {
            Log.d("PICTURE", "ON PICTURE TAKEN START");

            Intent intent = getIntent();

            final boolean beds = intent.getExtras().getBoolean(Main.BEDS, false);
            final boolean nurse = intent.getExtras().getBoolean(Main.NURSE, false);
            final int position = intent.getExtras().getInt(Main.POSITION, 0);

            if(beds)
            {
                BedroomDataSource bedDs = new BedroomDataSource(CameraActivityTest.this);
                String where = SQLiteBedroomHelper.COLUMN_UID + "=" + AppData.getBedrooms().get(position).getUid();
                bedDs.open();
                bedDs.updateBedroom(where, null, null, null, null, null, null, data);
                bedDs.close();
                Log.d("PICTURE", "BEDS BOOLEAN");
                AppData.getBedrooms().get(position).setImage(data);
            }else if(nurse)
            {

            }

            Log.d("PICTURE", "ON PICTURE TAKEN END");

            finish();
        }
    };

    btnCapture.setOnClickListener(new View.OnClickListener() 
    {   
        @Override
        public void onClick(View arg0) 
        {               
            camera.takePicture(shutterCallback, mPictureRaw, mPictureJpg);
        }
    });
}

@Override public void surfaceCreated(SurfaceHolder holder)
{
    camera = Camera.open();

    Camera.Parameters params = camera.getParameters();      

    params.setPreviewSize(holder.getSurfaceFrame().width(), holder.getSurfaceFrame().height());
    params.setPictureSize(32, 32);
    params.setJpegQuality(100);

    camera.setParameters(params);

    try
    {
        camera.setPreviewDisplay(holder);
    }catch(IOException ex){
        Log.d("PICTURE", "PREVIEW EXCEPTION");
    }

    camera.startPreview();

    Log.d("PICTURE", "SURFACE CREATED");
}

@Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)
{
    Log.d("PICTURE", "SURFACE CHANGED");
}

@Override public void surfaceDestroyed(SurfaceHolder holder)
{
    camera.stopPreview();

    camera.release();

    Log.d("PICTURE", "SURFACE DESTROYED");
}
}

Thanks.

EDIT: Looks like that some photos are taken and the callback is reached. The database gets the photos, and loads back in bitmap just fine. But depending on what I'm taking a photo of, the callback isn't reaching. Smaller and simpler things are 100% chance the callback will be executed.

Community
  • 1
  • 1
Comic Sans MS Lover
  • 1,729
  • 5
  • 26
  • 52

1 Answers1

-1

It looks like you create the callback mPicture, and then never set it as the callback for anything. I've never used any picture stuff, so I can't advise on where to set it, but as far as I know you need to register the callback for it to be called, just defining it won't do you any good.

dwemthy
  • 471
  • 3
  • 9
  • I wish that was the case :( It does work like this. In the camera.takePicture line, I actually define mPicture should be called. Thanks for your input. – Comic Sans MS Lover Apr 24 '12 at 15:04