I'm scanning files using MediaScanner
. But API 28 and 29 don't work.
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, file));
I used Broadcast
, but it didn't work the same way. Because it is "deprecated".
java public static class FilesScanner extends ContextWrapper implements MediaScannerConnection.MediaScannerConnectionClient{
private MediaScannerConnection connection = null;
private String SCAN_FILE_PATH = "";
private String SCAN_FILE_MIME_TYPE = "*/*";
public static FilesScanner with(Context context, String SCAN_FILE_PATH){ return new FilesScanner(context, SCAN_FILE_PATH, "*/*"); }
public static FilesScanner with(Context context, String SCAN_FILE_PATH, String SCAN_FILE_MIME_TYPE){ return new FilesScanner(context, SCAN_FILE_PATH, SCAN_FILE_MIME_TYPE); }
private FilesScanner(Context context, String SCAN_FILE_PATH, String SCAN_FILE_MIME_TYPE){
super(context);
this.SCAN_FILE_PATH = SCAN_FILE_PATH;
if (SCAN_FILE_PATH == null){
this.SCAN_FILE_PATH = FilePaths.ROOT_DIR;
}
this.SCAN_FILE_MIME_TYPE = SCAN_FILE_MIME_TYPE;
if (SCAN_FILE_MIME_TYPE == null){
this.SCAN_FILE_MIME_TYPE = "*/*";
}
connection = new MediaScannerConnection(this, this);
connection.connect();
}
@Override
public void onMediaScannerConnected() {
MyLog.d("onMediaScannerConnected");
connection.scanFile(SCAN_FILE_PATH, SCAN_FILE_MIME_TYPE);
}
@Override
public void onScanCompleted(String path, Uri uri) {
MyLog.d("onScanCompleted" + " URI : " + uri.getPath());
connection.disconnect();
}
}
FilesScanner.with(this, path, "image/*");