فهرست منبع

insert uploaded image to mediaStore

Signed-off-by: Abdourahamane BOINAIDI <abdourahamane.boinaidi@infomaniak.com>
Abdourahamane BOINAIDI 5 سال پیش
والد
کامیت
57de283d58

+ 22 - 4
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -1736,10 +1736,28 @@ public class FileDataStorageManager {
     }
 
     public static void triggerMediaScan(String path) {
-        if (path != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
-            Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
-            intent.setData(Uri.fromFile(new File(path)));
-            MainApp.getAppContext().sendBroadcast(intent);
+        triggerMediaScan(path, null);
+    }
+
+    public static void triggerMediaScan(String path, OCFile file) {
+        if (path != null) {
+            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);
+            }
         }
     }
 

+ 1 - 1
src/main/java/com/owncloud/android/operations/UploadFileOperation.java

@@ -1348,7 +1348,7 @@ public class UploadFileOperation extends SyncOperation {
         getStorageManager().saveConflict(file, null);
 
         if (MimeTypeUtil.isMedia(file.getMimeType())) {
-            FileDataStorageManager.triggerMediaScan(file.getStoragePath());
+            FileDataStorageManager.triggerMediaScan(file.getStoragePath(), file);
         }
 
         // generate new Thumbnail