Troj
Troj

Reputation: 11911

Android: using camera help, take a picture and use it on my app

I have created a startcam from my app.. and this is how the cam activity looks like.. I don't know how to klick to take a picture, where is the button?

What I want to do is also that when he has taken the picture and he is statiesfied, he click on a "finished button" so the picture will be shown on my app.

alt text

Upvotes: 1

Views: 2894

Answers (4)

Vishnu
Vishnu

Reputation: 1

Please Enable the Camera in your emulator settings. You should make the emulator settings as:

camera support = yes

I think this feature is available from Android 4.0 version, but I'm not sure about it.

Upvotes: 0

Matt
Matt

Reputation: 2680

You can debug a camera app on a physical device using USB debugging.

To take and save the picture, you will need a callback similar to this: `

Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {

        try {
            File sdTargetDirectory = new File("/sdcard/directory");
            sdTargetDirectory.mkdirs();  // make the above directory if it does not exist
            FileOutputStream fos = null;
            String fileName = "temp";

            Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);

            fos = new FileOutputStream(sdTargetDirectory.toString() +"/" + fileName + ".jpg");

            BufferedOutputStream bos = new BufferedOutputStream(fos);

            bitmap.compress(CompressFormat.JPEG, 100, bos);

            bos.flush();
            bos.close();


        } 
        catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
};

You can implement that callback in a touch or button event like this:

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        camera.takePicture(null, null, mPictureCallback);
        break;
    }
    return true;
}

Upvotes: 1

Shawn Lauzon
Shawn Lauzon

Reputation: 6282

I see the same thing on developers.android.com, but my emulator has a working camera application. The camera button on the emulator itself doesn't do anything, but I can access it from my app, and it gives me a camera like this:

Android emulator camera

You see the button at the bottom left takes the picture, then an OK button pops up, which returns it to your code.

My emulator settings are:

  • Android 1.6 (API Level 4)
  • Skin: HVGA
  • SD Card: 1024M
  • hw.lcd.densite: 160

I believe you need the SD Card, not sure about anything else.

Upvotes: 1

blindstuff
blindstuff

Reputation: 18348

You cant take pictures using the emulator, i've heard there is a library out there that uses a webcam to integrate the functionality, but I havent used it so it might be a mith.

So, sorry to say, but you need a device to test that.

Per developers.android.com:

Emulator Limitations In this release, the limitations of the emulator include:

  • No support for placing or receiving actual phone calls. You can simulate phone calls (placed and received) through the emulator console, however.
  • No support for USB connections
  • No support for camera/video capture (input).
  • No support for device-attached headphones
  • No support for determining connected state
  • No support for determining battery charge level and AC charging state
  • No support for determining SD card insert/eject
  • No support for Bluetooth

Hopefuly someday they will add it.

Upvotes: 1

Related Questions