1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Delete files properly from MediaStore (fixes #983)

This commit is contained in:
Felix Ableitner 2017-11-05 21:31:34 +09:00
parent 06e3bee3df
commit 433829036d

View file

@ -1,12 +1,15 @@
package com.nutomic.syncthingandroid.service; package com.nutomic.syncthingandroid.service;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.media.MediaScannerConnection;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.provider.MediaStore;
import android.util.Log; import android.util.Log;
import com.annimon.stream.Stream; import com.annimon.stream.Stream;
@ -144,11 +147,20 @@ public class EventProcessor implements SyncthingService.OnWebGuiAvailableListene
folderPath = f.path; folderPath = f.path;
} }
} }
File updatedFile = new File(folderPath, File updatedFile = new File(folderPath, (String) event.data.get("item"));
(String) event.data.get("item")); if (!"delete".equals(event.data.get("action"))) {
Log.i(TAG, "Notified media scanner about " + updatedFile.toString()); Log.i(TAG, "Rescanned file via MediaScanner: " + updatedFile.toString());
mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Log.d("xxx", "update intent sent for " + updatedFile.getName());
Uri.fromFile(updatedFile))); MediaScannerConnection.scanFile(mContext, new String[]{updatedFile.getPath()},
null, null);
} else {
// https://stackoverflow.com/a/29881556/1837158
Log.i(TAG, "Deleted file from MediaStore: " + updatedFile.toString());
Uri contentUri = MediaStore.Files.getContentUri("external");
ContentResolver resolver = mContext.getContentResolver();
resolver.delete(contentUri, MediaStore.Images.ImageColumns.DATA + " LIKE ?",
new String[]{updatedFile.getPath()});
}
break; break;
case "Ping": case "Ping":
// Ignored. // Ignored.