Android摄像头不保存图片

Android摄像头不保存图片,android,android-camera,Android,Android Camera,嘿,我正在编写代码来捕获图像,但我的onPictureTaken方法从未被调用…我哪里出错了 我的代码是 btnCapture.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { cam.takePicture(null, null, new TakeMyPicture()); } }); c

嘿,我正在编写代码来捕获图像,但我的onPictureTaken方法从未被调用…我哪里出错了

我的代码是

btnCapture.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            cam.takePicture(null, null, new TakeMyPicture());
        }
    });



   class TakeMyPicture implements PictureCallback
{

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        imagebytearray=data;            
        Toast.makeText(getApplicationContext(), "Image Captured",5).show();
    }

}
完全脱离

申请使用相机的许可

<uses-feature android:name="android.hardware.camera" />
保存照片

storageDir = new File(
    Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_PICTURES
    ), 
    getAlbumName()
);
设置文件名

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = 
        new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";
    File image = File.createTempFile(
        imageFileName, 
        JPEG_FILE_SUFFIX, 
        getAlbumDir()
    );
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}
通过Intent将位置传递给摄像头应用程序

File f = createImageFile();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));

LogCat中有任何值得注意的消息吗?您确定调用过
onClick()
吗?OP直接使用
Camera
类,而不是
Intent
File f = createImageFile();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));