Android: Getting file name from camera?

I ran into a problem with something that I probably just overlooked.

I want to take a preview of the surface of the camera and save it on sd_card. It works almost perfectly. I assigned him a file name, but it does not use filename.

Here is what I tried to do:

Button imagecapture = (Button) findViewById(R.id.imagecapture);
imagecapture.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        String filename = null;
        ImageCaptureCallback iccb = null;

        try {
            filename = timeStampFormat.format(new Date());
            ContentValues values = new ContentValues();
            values.put(Media.TITLE, filename);
            values.put(Media.DESCRIPTION, "Image capture by camera");

            Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
            iccb = new ImageCaptureCallback(getContentResolver().openOutputStream(uri));
        } catch (Exception ex) {
            ex.printStackTrace();
            Log.e(getClass().getSimpleName(), ex.getMessage(), ex);
        }
        camera.takePicture(mShutterCallback, mPictureCallbackRaw, iccb);
        com.froogloid.android.gspot.Park.imageFileName = filename;
    }
});

It will not use the file name (i.e. time / date, I ask for it).

+7
source share
3 answers

This was resolved by implementing PictureCallback through the ImageCaptureCallback class and overriding onPictureTaken where the file was written through the file output stream. All you had to do was change the file stream stream to the desired file name.

+6

? , , "filaname" SD-? sdcard , examople, "fileUri" uri.toString, end get from sdcard file uri Uri.parse(fileUri)..

0

, /, , . :
.

public class ImageCaptureCallback implements PictureCallback {

    private OutputStream filoutputStream;
    public ImageCaptureCallback(OutputStream filoutputStream) {
        this.filoutputStream = filoutputStream;
    }

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

        try {
            Log.v(getClass().getSimpleName(), "onPictureTaken=" + data + " length = " + data.length);
            FileOutputStream buf = new FileOutputStream("/sdcard/dcim/Camera/" + CameraActivity.filename + ".jpg");
            buf.write(data);
            buf.flush();
            buf.close();
            // filoutputStream.write(data);
            filoutputStream.flush();
            filoutputStream.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
0

All Articles