|
36 | 36 | import android.content.OperationApplicationException; |
37 | 37 | import android.database.Cursor; |
38 | 38 | import android.net.Uri; |
| 39 | +import android.os.Build; |
| 40 | +import android.os.FileUriExposedException; |
39 | 41 | import android.os.RemoteException; |
40 | 42 | import android.provider.MediaStore; |
41 | 43 |
|
@@ -1713,18 +1715,24 @@ public ArrayList<OCShare> getPublicSharesForAFile(String filePath, String accoun |
1713 | 1715 | public void triggerMediaScan(String path) { |
1714 | 1716 | if (path != null) { |
1715 | 1717 | 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); |
1726 | 1735 | } |
1727 | | - MainApp.getAppContext().sendBroadcast(intent); |
1728 | 1736 | } |
1729 | 1737 | } |
1730 | 1738 |
|
|
0 commit comments