Skip to content

Commit

Permalink
Merge pull request #2613 from owncloud/fix/trigger_media_scan
Browse files Browse the repository at this point in the history
Fix trigger media scan
  • Loading branch information
davigonz authored Aug 2, 2019
2 parents b6bc623 + 29f0906 commit e1c49f7
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.os.FileUriExposedException;
import android.os.RemoteException;
import android.provider.MediaStore;

Expand Down Expand Up @@ -1713,18 +1715,24 @@ public ArrayList<OCShare> getPublicSharesForAFile(String filePath, String accoun
public void triggerMediaScan(String path) {
if (path != null) {
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
try {
intent.setData(
FileProvider.getUriForFile(
mContext.getApplicationContext(),
mContext.getResources().getString(R.string.file_provider_authority),
new File(path)
)
);
} catch (IllegalArgumentException illegalArgumentException) {
intent.setData(Uri.fromFile(new File(path)));
intent.setData(Uri.fromFile(new File(path)));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
MainApp.getAppContext().sendBroadcast(intent);
} catch (FileUriExposedException fileUriExposedException) {
Intent newIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
newIntent.setData(FileProvider.getUriForFile(
mContext.getApplicationContext(),
mContext.getResources().getString(R.string.file_provider_authority),
new File(path)
)
);
MainApp.getAppContext().sendBroadcast(newIntent);
}
} else {
MainApp.getAppContext().sendBroadcast(intent);
}
MainApp.getAppContext().sendBroadcast(intent);
}
}

Expand Down

0 comments on commit e1c49f7

Please sign in to comment.