I am unable to compress a file on all devices in java in android studio. It works on some android versions but not on all. I am uploading a profile picture in my application, but to upload large files I am compressing it to so as to easily upload it. But the method which I am using for compressing the file is working on some android versions but not on all.
I've tried many methods, I've resized my picture so as to reduce its size but at last the compressing method suits the most to my code and it was working fine for some devices but not for all.
private File getBitmapFile(Bitmap reducedBitmap, File file1) {
File file = new File(Environment.getExternalStorageDirectory() + File.separator + file1.getName());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
reducedBitmap.compress(Bitmap.CompressFormat.JPEG,100,bos);
byte[] bitmapdata = bos.toByteArray();
Log.e(""," Working: ");
try{
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
fos.write(bitmapdata);
fos.flush();
fos.close();
return file;
} catch (Exception e){
e.printStackTrace();
}
return file;
}