Messaging: Migrate attachments to MediaStore
* Saving them doesn't work otherwise * We don't have to care about MediaScanner and DownloadManager anymore that way, either Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/8573 Change-Id: I7a3b1dc6916feff4849bdfa2b8937460c32bc5a2 Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com> (cherry picked from commit 93bd39838d4a395dd710796b0e71ada1ec1f5ff2)
This commit is contained in:
@@ -258,14 +258,12 @@ public class UriUtil {
|
||||
|
||||
/**
|
||||
* Persist a piece of content from the given sourceUri, byte by byte to the
|
||||
* specified output directory.
|
||||
* @return the output Uri if the operation succeeded, or null if failed.
|
||||
* specified targetUri.
|
||||
*/
|
||||
@DoesNotRunOnMainThread
|
||||
public static Uri persistContent(
|
||||
final Uri sourceUri, final File outputDir, final String contentType) {
|
||||
public static void persistContent(
|
||||
final Context context, final Uri sourceUri, final Uri targetUri) {
|
||||
InputStream inputStream = null;
|
||||
final Context context = Factory.get().getApplicationContext();
|
||||
try {
|
||||
if (UriUtil.isLocalResourceUri(sourceUri)) {
|
||||
inputStream = context.getContentResolver().openInputStream(sourceUri);
|
||||
@@ -273,13 +271,12 @@ public class UriUtil {
|
||||
// The content is remote. Download it.
|
||||
inputStream = getInputStreamFromRemoteUri(sourceUri);
|
||||
if (inputStream == null) {
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return persistContent(inputStream, outputDir, contentType);
|
||||
copyContent(context, inputStream, targetUri);
|
||||
} catch (final Exception ex) {
|
||||
LogUtil.e(LogUtil.BUGLE_TAG, "Error while retrieving media ", ex);
|
||||
return null;
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user