Unable to save image file in android oreo update. How to do it?

后端 未结 2 1620
难免孤独
难免孤独 2020-11-27 22:38

I can\'t save an image file in android oreo(8.0) api 26.
The code is working perfectly in api level 25 (7.0) and I didn\'t find any changes in the documentation \"Androi

2条回答
  •  我在风中等你
    2020-11-27 23:09

    I am also experiencing the same issue and i am stuck with this issue from 2 months. I have already given permission for WRITE_EXTERNAL_STORAGE in the manifest first and also again checking is it have write permission. I think it is not a permission issue. Because when i test with oreo the folder is creating and there is a corrupted image file in the folder i am creating. Because of that it is not coming to the gallery and then on save it returns me Image not captured. I am getting this problem only in android 7.1.1 and oreo. Upto android 7.0 it is working fine. I have checked with devices samsung galaxy note 8 and google pixel xl 2. I am using a custom camera with with gps and below function

    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);
                            save(bytes);
    

    for image byte save and the save function contains the code below

    OutputStream output = null;
                        try {
                            output = new FileOutputStream(finalFile);
                            output.write(bytes);
                        } finally {
                            if (null != output) {
                                output.close();
                            }
                        }
    

提交回复
热议问题