activityForResult没有额外的东西,试图启动相机

时间:2017-04-05 18:36:56

标签: android android-camera-intent

按下按钮,我产生了拍照的意图。我的目标是在屏幕上显示缩略图位图,并将完整尺寸的图像保存在手机上,以备日后使用。

public void takePicture(View v) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            mImageUri = FileProvider.getUriForFile(this,
                    "com.acme.hello.world.fileprovider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }
}

这就是我对请求的回应:

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

    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == -1 /*RESULT_OK*/) {

        try {

            Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
            Log.d(TAG, String.format("%sx%s", thumbnail.getWidth(), thumbnail.getHeight()));
            Bitmap full = MediaStore.Images.Media.getBitmap(this.getContentResolver(), mImageUri);
            Log.d(TAG, String.format("%sx%s", full.getWidth(), full.getHeight()));

            // TODO: Consider deleting the file off the device, or warn when out of memory

        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

问题是data.getExtras()返回null。

当我按照Android文档提供的these说明时,不确定我做错了什么。

编辑:看起来Android没有写缩略图和完整图像

0 个答案:

没有答案