IMAGE_CAPTURE无法在某些Android设备中返回

时间:2014-03-20 03:03:29

标签: android

我需要在我的应用程序中拍照,这是核心代码:

跳跳虎:

mPhotoToBeUpload = new File(mImageBasePath, System.currentTimeMillis() + ".jpg");
try {
    mPhotoToBeUpload.mkdirs();
    mPhotoToBeUpload.createNewFile();
} catch (IOException e) {
    Log.e("xx",e.getMessage());
}

Uri outputFileUri = Uri.fromFile(mPhotoToBeUpload);

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

startActivityForResult(cameraIntent, Result_Code_Camera);

结果处理程序:

protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
    if (resultCode == RESULT_OK) {
        Bitmap photoTaken = BitmapFactory.decodeFile(mPhotoToBeUpload.getAbsolutePath());
        mImageView.setImageBitmap(photoTaken);
    } else
}

但是我发现这些代码在某些设备中有效,但在其他设备中却没有。

例如,它们不适用于Nexus 4和Nexus5。

虽然我说他们不起作用,但我的意思是在拍完照片后点击OK按钮后,我无法回到之前的活动:

enter image description here

当我点击OK(红色圆圈内的图标)时,它无效。

有什么问题?


UPADTE:

private final String mImageBasePath = Environment.getExternalStorageDirectory() + File.separator + IConstant.Application_Folder + File.separator + "photos";
mPhotoToBeUpload = new File(mImageBasePath, System.currentTimeMillis() + ".jpg");

结果:mPhotoToBeupLoad=/storage/emulated/0/myapp/photos/1395287647386.jpg

2 个答案:

答案 0 :(得分:0)

显示mImageBasePath的路径是什么,因为当文件路径无效时,这个问题通常会发生。

答案 1 :(得分:0)

通过引用此问题解决:Android ACTION_IMAGE_CAPTURE Intent

而不是

Uri outputFileUri = Uri.fromFile(mPhotoToBeUpload);

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

startActivityForResult(cameraIntent, Result_Code_Camera);

使用:

URI mPhotoToBeUploadURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoToBeUploadURI);