|
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 |
|
@@ -1714,22 +1716,23 @@ public void triggerMediaScan(String path) { |
1714 | 1716 | if (path != null) { |
1715 | 1717 | Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); |
1716 | 1718 | intent.setData(Uri.fromFile(new File(path))); |
1717 | | - MainApp.getAppContext().sendBroadcast(intent); |
1718 | 1719 |
|
1719 | | - // For making uploads and downloads work in wrapped apps |
1720 | | - Intent wrappedAppintent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); |
1721 | | - try { |
1722 | | - Uri uri = FileProvider.getUriForFile( |
1723 | | - mContext.getApplicationContext(), |
1724 | | - mContext.getResources().getString(R.string.file_provider_authority), |
1725 | | - new File(path) |
1726 | | - ); |
1727 | | - wrappedAppintent.setData(uri); |
1728 | | - } catch (IllegalArgumentException illegalArgumentException) { |
1729 | | - wrappedAppintent.setData(Uri.fromFile(new File(path))); |
| 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); |
1730 | 1735 | } |
1731 | | - |
1732 | | - MainApp.getAppContext().sendBroadcast(wrappedAppintent); |
1733 | 1736 | } |
1734 | 1737 | } |
1735 | 1738 |
|
|
0 commit comments