GOAL: To perform compression on image/content
, retrieved through external sources (ex: sd-card, internal or drive) using intent.
I was able to get actual path for the retrieved content, but when i am trying to compress it using compression library (zetbaitsu/Compressor) its throwing error
open failed: EACCES (Permission denied).
I have cross checked my permissions and tried multiple way to confirm permission access, still its throwing error.
Here is my function:
void handleSendImage(Intent intent) {
try {
Uri imageUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
Log.d(TAG, "handleSendImage: " + imageUri.toString());
File imageFile = new File(getFilePath(this, imageUri));
Log.d(TAG, "handleSendImage: " + Uri.fromFile(imageFile));
File compressedFile = new Compressor(this).compressToFile(imageFile);
} catch (Exception e) {
Log.e(TAG, "handleSendImage: " + e.getMessage());
}
}
Here are my logs outputs:
handleSendImage: content://com.android.providers.media.documents/document/image%3A30
handleSendImage: file:///storage/emulated/0/Download/4c568534307d605ed94878dc06d933ee.jpg
handleSendImage: /storage/emulated/0/Download/4c568534307d605ed94878dc06d933ee.jpg: open failed: EACCES (Permission denied)
android:requestLegacyExternalStorage="true"
Add this in Manifest file but this won't work in android 11