Skip to content

Commit e1c49f7

Browse files
authored
Merge pull request #2613 from owncloud/fix/trigger_media_scan
Fix trigger media scan
2 parents b6bc623 + 29f0906 commit e1c49f7

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

owncloudApp/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import android.content.OperationApplicationException;
3737
import android.database.Cursor;
3838
import android.net.Uri;
39+
import android.os.Build;
40+
import android.os.FileUriExposedException;
3941
import android.os.RemoteException;
4042
import android.provider.MediaStore;
4143

@@ -1713,18 +1715,24 @@ public ArrayList<OCShare> getPublicSharesForAFile(String filePath, String accoun
17131715
public void triggerMediaScan(String path) {
17141716
if (path != null) {
17151717
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
1716-
try {
1717-
intent.setData(
1718-
FileProvider.getUriForFile(
1719-
mContext.getApplicationContext(),
1720-
mContext.getResources().getString(R.string.file_provider_authority),
1721-
new File(path)
1722-
)
1723-
);
1724-
} catch (IllegalArgumentException illegalArgumentException) {
1725-
intent.setData(Uri.fromFile(new File(path)));
1718+
intent.setData(Uri.fromFile(new File(path)));
1719+
1720+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
1721+
try {
1722+
MainApp.getAppContext().sendBroadcast(intent);
1723+
} catch (FileUriExposedException fileUriExposedException) {
1724+
Intent newIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
1725+
newIntent.setData(FileProvider.getUriForFile(
1726+
mContext.getApplicationContext(),
1727+
mContext.getResources().getString(R.string.file_provider_authority),
1728+
new File(path)
1729+
)
1730+
);
1731+
MainApp.getAppContext().sendBroadcast(newIntent);
1732+
}
1733+
} else {
1734+
MainApp.getAppContext().sendBroadcast(intent);
17261735
}
1727-
MainApp.getAppContext().sendBroadcast(intent);
17281736
}
17291737
}
17301738

0 commit comments

Comments
 (0)