Android 中无法在 Camera Intent 上保存全尺寸照片
Can't save the Full-Sized Photo on Camera Intent in Android
读完教程后Taking Photos Simply,我试着按照教程中的方法去做。
问题是在我的 OnePlus X 上它可以工作。如果我使用其他手机,如 Samsung Galaxy S5 或 S6 或任何其他设备,它就无法工作。
pictureActionIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (pictureActionIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
e.printStackTrace();
}
if (photoFile != null) {
//pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
}
}
startActivityForResult(pictureActionIntent, CAMERA_REQUEST);
如果我删除评论,onActivityResult
中的data
就是null
。
如果我设置评论,data
看起来(在三星设备上)像:
data = {android.content.Intent@19974} "Intent{act=inline-data dat=content://Media/external/images/media/16123 (has extras)}"
那么,问题出在哪里呢?我需要更改什么才能使其在所有设备上都能正常工作?
感谢您的帮助!
亲切的问候!
您还需要传递图像 URL。
intent.putExtra( MediaStore.EXTRA_OUTPUT, _fileUri);
然后就可以使用这个文件路径了
编辑
private void saveFullImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == TAKE_PICTURE) && (resultCode == Activity.RESULT_OK)) {
// Check if the result includes a thumbnail Bitmap
if (data == null) {
// TODO Do something with the full image stored
// in outputFileUri. Perhaps copying it to the app folder
}
}
}
读完教程后Taking Photos Simply,我试着按照教程中的方法去做。
问题是在我的 OnePlus X 上它可以工作。如果我使用其他手机,如 Samsung Galaxy S5 或 S6 或任何其他设备,它就无法工作。
pictureActionIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (pictureActionIntent.resolveActivity(getPackageManager()) != null) {
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
e.printStackTrace();
}
if (photoFile != null) {
//pictureActionIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
}
}
startActivityForResult(pictureActionIntent, CAMERA_REQUEST);
如果我删除评论,onActivityResult
中的data
就是null
。
如果我设置评论,data
看起来(在三星设备上)像:
data = {android.content.Intent@19974} "Intent{act=inline-data dat=content://Media/external/images/media/16123 (has extras)}"
那么,问题出在哪里呢?我需要更改什么才能使其在所有设备上都能正常工作?
感谢您的帮助!
亲切的问候!
您还需要传递图像 URL。
intent.putExtra( MediaStore.EXTRA_OUTPUT, _fileUri);
然后就可以使用这个文件路径了
编辑
private void saveFullImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "test.jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if ((requestCode == TAKE_PICTURE) && (resultCode == Activity.RESULT_OK)) {
// Check if the result includes a thumbnail Bitmap
if (data == null) {
// TODO Do something with the full image stored
// in outputFileUri. Perhaps copying it to the app folder
}
}
}