Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.RemoteException;
import android.provider.MediaStore;
import android.text.TextUtils;
Expand Down Expand Up @@ -380,7 +381,7 @@ public void saveFolder(OCFile folder, Collection<OCFile> updatedFiles, Collectio
if (file.isDown()) {
String path = file.getStoragePath();
if (new File(path).delete() && MimeTypeUtil.isMedia(file.getMimeType())) {
triggerMediaScan(path); // notify MediaScanner about removed file
triggerMediaScan(path, file); // notify MediaScanner about removed file
}
}
}
Expand Down Expand Up @@ -1735,10 +1736,28 @@ public List<OCShare> getSharesWithForAFile(String filePath, String accountName)
}

public static void triggerMediaScan(String path) {
triggerMediaScan(path, null);
}

public static void triggerMediaScan(String path, OCFile file) {
if (path != null) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(path)));
MainApp.getAppContext().sendBroadcast(intent);
ContentValues values = new ContentValues();
ContentResolver contentResolver = MainApp.getAppContext().getContentResolver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (file != null) {
values.put(MediaStore.Images.Media.MIME_TYPE, file.getMimeType());
values.put(MediaStore.Images.Media.TITLE, file.getFileName());
values.put(MediaStore.Images.Media.DISPLAY_NAME, file.getFileName());
}
values.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis() / 1000);
values.put(MediaStore.Images.Media.RELATIVE_PATH, path);
values.put(MediaStore.Images.Media.IS_PENDING, 0);
contentResolver.insert(MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY), values);
} else {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(new File(path)));
MainApp.getAppContext().sendBroadcast(intent);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private void saveDownloadedFile() {
file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
mStorageManager.saveFile(file);
if (MimeTypeUtil.isMedia(mCurrentDownload.getMimeType())) {
FileDataStorageManager.triggerMediaScan(file.getStoragePath());
FileDataStorageManager.triggerMediaScan(file.getStoragePath(), file);
}
mStorageManager.saveConflict(file, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void saveLocalFile() {
getStorageManager().deleteFileInMediaScan(oldPath);
// notify to scan about new file, if it is a media file
if (MimeTypeUtil.isMedia(file.getMimeType())) {
FileDataStorageManager.triggerMediaScan(newPath);
FileDataStorageManager.triggerMediaScan(newPath, file);
}
}
// else - NOTHING: the link to the local file is kept although the local name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ private void saveUploadedFile(OwnCloudClient client) {
getStorageManager().saveConflict(file, null);

if (MimeTypeUtil.isMedia(file.getMimeType())) {
FileDataStorageManager.triggerMediaScan(file.getStoragePath());
FileDataStorageManager.triggerMediaScan(file.getStoragePath(), file);
}

// generate new Thumbnail
Expand Down