拍照而不保存

时间:2016-06-23 12:57:47

标签: java android android-intent

我想调用android的原生相机,不要将它保存在存储器中,因为我在处理完图像后自己保存了它。除摩托罗拉XT1032(Android 5.1,API 22)外,它几乎适用于所有设备。那么有没有办法告诉相机不要保存图片? 以下是我调用相机意图的方法。

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.separator + "image_"+System.currentTimeMillis()+".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
((Activity) mContext).startActivityForResult(intent, 1001);

1 个答案:

答案 0 :(得分:0)

创建请求代码变量:

private static final int REQUEST_CAMERA = 1;

打开相机:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);

如果您想向用户展示:

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
case REQUEST_CAMERA:
                if (resultCode == RESULT_OK) {
                    // successfully captured the image

                    Bitmap mBitmap = (Bitmap) data.getExtras().get("data");
                    if (mBitmap != null) {
                      imageView.setImageBitmap(mBitmap);
                    }
}


}