我已经在清单中请求了WRITE_EXTERNAL_STORAGE
的权限,并且在运行时检查了我的写权限。
当我使用Oreo测试时,文件夹和临时文件已创建,但问题是它没有进入我试图将图像字节写入文件的部分。
我只在Android 7.1.1+中遇到此问题。高达Android 7.0,它工作正常。我已经检查了三星Galaxy Note 8和Google Pixel XL 2.我使用带GPS的自定义相机和以下代码:
This is the code i am using and the problem here in oreo is it is not entering to imagereader section ImageReader.OnImageAvailableListener. I got the problem by giving some alerts. So is there anyone to help me to find out why it is not entering to imagereader section?
String dateTimeOrg = new SimpleDateFormat(" yyyy_MM_dd_HH_mm_ss")。format(new Date())。toString();
try {
file = createTemporaryFile(dateTimeOrg, ".jpg");
} catch (Exception e) {
e.printStackTrace();
}
final File finalFile = file;
//end old working code
ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image image = null;
try {
image = reader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
// Need to remove it
final Toast toast = Toast.makeText(getApplicationContext(), "Going to Save", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER,0,0);
toast.show();
//End Need to remove it
save(bytes);
}
以下是保存图像的代码
OutputStream output = null;
try {
output = new FileOutputStream(finalFile);
output.write(bytes);
} finally {
if (null != output) {
output.close();
}
}