拍照期间的空白页

时间:2018-01-17 15:42:09

标签: java android android-camera

我正在尝试拍摄照片应用程序(教程here),但我的相机不想工作 - 它只是空白页,可能是Manifest或文件路径的问题,但我无法想象在哪里我犯了错误。

Manifest中的重要代码:

  <uses-feature android:name="android.hardware.camera"
    android:required="true" />
    <uses-permission 
    android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   android:maxSdkVersion="18" />

   <provider
   android:name="android.support.v4.content.FileProvider"
   android:authorities="com.lowcyandroidow.siekaczzdjecpro.fileprovider"
   android:exported="false"
   android:grantUriPermissions="true">
   <meta-data
   android:name="android.support.FILE_PROVIDER_PATHS"
   android:resource="@xml/file_paths" />
   </provider>

file_paths:

    <?xml version="1.0" encoding="utf-8"?>
    <paths>
    <files-path
    name="my_images"
    path="Android/data/com.lowcyandroidow.siekaczzdjecpro/files/Pictures" />
    </paths>

最后是Activity类:

     @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_take_picture);

    mImageView = (ImageView) findViewById(R.id.mImageView);
}


private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
        }
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.lowcyandroidow.siekaczzdjecpro.fileprovider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        mImageView.setImageBitmap(imageBitmap);
    }
}

private File createImageFile() throws IOException {
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,
            ".jpg",
            storageDir
    );
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

我错过了什么吗?

0 个答案:

没有答案