Closed Pajet closed 1 year ago
Hey! @GauthamAsir and @Pajet, I just found a method to download files in android 13 by using your content resolver uri.. here is the code:
ContentValues values = new ContentValues();
Uri destinationUri;
values.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName);
values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DCIM + "/status_saver/"+fileName);
Uri collectionUri;
if (status.isVideo()) {
values.put(MediaStore.MediaColumns.MIME_TYPE, "video/*");
collectionUri = MediaStore.Video.Media.getContentUri(
MediaStore.VOLUME_EXTERNAL_PRIMARY);
} else {
values.put(MediaStore.MediaColumns.MIME_TYPE, "image/*");
collectionUri = MediaStore.Images.Media.getContentUri(
MediaStore.VOLUME_EXTERNAL_PRIMARY);
}
destinationUri = context.getContentResolver().insert(collectionUri, values);
InputStream inputStream = context.getContentResolver().openInputStream(status.getDocumentFile().getUri());
OutputStream outputStream = context.getContentResolver().openOutputStream(destinationUri);
Log.d(TAG, "setFileLocked: ");
IOUtils.copy(inputStream, outputStream);
You can update your code now...
You are a legend @Waleed055 Thanx
@Waleed055 Thanks for the contribution,
Code has been updated. Revive Download Button
@GauthamAsir Copying status images and videos works perfectly with devices below Android 10 while using File in copyFile() in Utils. However, it seems like there is an issue while using DocumentFile in the same method for copying statuses Android 11 and above. Is there a fix to downloading using DocumentFile?
I tried using MediaStore as an alternative to save but turns out I am saving the thumbnail and not the actual file using bitmap and FileOutputstream.