Camera and Gallery image not saved

Asked

Viewed 12 times

-1

I wrote a code in Android Studio java, SQLITE with image gallery and camera using the SAMSUNG A5 2017 as emulator. When running all fields were saved normally. I switched to the GALAXY S20 FE. When rotating only the field of the image is not saved and does not appear no error message. Can someone help me?

Permissions in the Manifest:

To Save the Image use: Private string saveImage(Bitmap bitmap){ Bytearrayoutputstream bytes = new Bytearrayoutputstream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 50 bytes); File directory = new File(Environment.getExternal);

    if (!directory.exists()){
        directory.mkdirs();
    }
    try {
        File f = new File(directory, Calendar.getInstance().getTimeInMillis() + ".jpg");
        f.createNewFile();
        FileOutputStream fo = new FileOutputStream(f);
        fo.write(bytes.toByteArray());

        MediaScannerConnection.scanFile(this, new String[]{f.getPath()}, new String[]{"image/jpeg"}, null);
        fo.close();
        return f.getAbsolutePath();

    }catch (IOException e){
        e.printStackTrace();
    }
    return "";
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.