我正在尝试使相机将文件存储在内部文件存储中,在Marshmellow及以上版本中一切运行正常,但在Lollipop及以下版本中,相机无法在内部存储中创建和存储文件
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mFile));
}
else
{
Uri photoUri = FileProvider.getUriForFile(activityReference.getApplicationContext(), activityReference.getPackageName() + ".provider", mFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
}
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (fragmentReference == null)
activityReference.startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
else
fragmentReference.startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
在onActivityResult
中,每当我传递内部文件存储中存在的文件(context.getFilesDir())时,我总是得到Activity.RESULT_CANCELED
,当文件存在于外部缓存,外部文件或外部文件中时,一切正常公共目录