How to compress an image file in Android?
<p>So for each image I have its path (in the form of a string). And I convert that path string to a file. I then store that file into Firebase storage, but my problem is that the file is too large when I query. So I need to compress it before uploading it Firebase storage. I was looking around, but never found a clear cut solution on how to do this. Please if anyone can help me with very clear and simple solution that would be great. Below is my code.</p>

<pre><code>for(String path : images)
{
    try {
    InputStream stream = new FileInputStream(new File(path));
    UploadTask uploadTask = imageStorage.putStream(stream);
    uploadTask.addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception exception) {
            // Handle unsuccessful uploads
            Log.d("myStorage","failure :(");
        }
    }).addOnSuccessListener(new OnSuccessListener&lt;UploadTask.TaskSnapshot&gt;() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
            UrI downloadUrl = taskSnapshot.getDownloadUrl();
            Log.d("myStorage","success!");
        }
    });
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    }
    countDB++;

}
</code></pre>