android.media.MediaScannerConnection Java Examples

The following examples show how to use android.media.MediaScannerConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SingleMediaScanner.java    From cordova-rtmp-rtsp-stream with Apache License 2.0 8 votes vote down vote up
@Override
public void onScanCompleted(String path, Uri uri) {
    Log.i("SingleMediaScanner", path);
    Log.i("SingleMediaScanner", uri.getPath());

    mMs.disconnect();

    MediaScannerConnection.scanFile(mContext, new String[] { mFile.getAbsolutePath() }, new String[] { "video/*" }, null);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    {
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        mediaScanIntent.setData(Uri.fromFile(mFile));
        mContext.sendBroadcast(mediaScanIntent);
    }
    else
    {
        mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(mFile.getAbsolutePath())));
    }
}
 
Example #2
Source File: RecorderVideoActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
public void sendVideo(View view) {
	if (TextUtils.isEmpty(localPath)) {
		EMLog.e("Recorder", "recorder fail please try again!");
		return;
	}

	msc = new MediaScannerConnection(this,
			new MediaScannerConnectionClient() {

				@Override
				public void onScanCompleted(String path, Uri uri) {
					System.out.println("scanner completed");
					msc.disconnect();
					setResult(RESULT_OK, getIntent().putExtra("uri", uri));
					finish();
				}

				@Override
				public void onMediaScannerConnected() {
					msc.scanFile(localPath, "video/*");
				}
			});
	msc.connect();

}
 
Example #3
Source File: ImageSaver.java    From Pixiv-Shaft with MIT License 6 votes vote down vote up
void execute() {
    File file = whichFile();
    if (file == null) {
        return;
    }

    String[] path = new String[1];
    String[] mime = new String[1];
    String filePath = file.getPath();
    Common.showLog("ImageSaver before " + filePath);
    path[0] = filePath;
    if (filePath.endsWith(".gif")) {
        mime[0] = "image/gif";
    } else if (filePath.endsWith(".jpeg") || filePath.endsWith(".jpg")) {
        mime[0] = "image/jpeg";
    } else {
        mime[0] = "image/png";
    }
    MediaScannerConnection.scanFile(
            Shaft.getContext(), path, mime, (path1, uri) -> {
            }
    );
}
 
Example #4
Source File: SaveAttachmentTask.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private @Nullable String saveAttachment(Context context, Attachment attachment)
    throws NoExternalStorageException, IOException
{
  String      contentType = MediaUtil.getCorrectedMimeType(attachment.contentType);
  String         fileName = attachment.fileName;

  if (fileName == null) fileName = generateOutputFileName(contentType, attachment.date);
  fileName = sanitizeOutputFileName(fileName);

  File    outputDirectory = createOutputDirectoryFromContentType(contentType);
  File          mediaFile = createOutputFile(outputDirectory, fileName);
  InputStream inputStream = PartAuthority.getAttachmentStream(context, attachment.uri);

  if (inputStream == null) {
    return null;
  }

  OutputStream outputStream = new FileOutputStream(mediaFile);
  Util.copy(inputStream, outputStream);

  MediaScannerConnection.scanFile(context, new String[]{mediaFile.getAbsolutePath()},
                                  new String[]{contentType}, null);

  return outputDirectory.getName();
}
 
Example #5
Source File: ConfigActivity.java    From Field-Book with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Scan file to update file list and share exported file
 */
private void shareFile(File filePath) {
    MediaScannerConnection.scanFile(this, new String[]{filePath.getAbsolutePath()}, null, null);

    if (!ep.getBoolean(GeneralKeys.DISABLE_SHARE, false)) {
        Intent intent = new Intent();
        intent.setAction(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".fileprovider", filePath));
        try {
            startActivity(Intent.createChooser(intent, "Sending File..."));
        } catch (Exception e) {
            Log.e("Field Book", "" + e.getMessage());
        }
    }
}
 
Example #6
Source File: DownloadPostFragment.java    From Instagram-Profile-Downloader with MIT License 6 votes vote down vote up
protected void onPostExecute(List<String> list) {
    progressDialog.dismiss();
    try {
        Toast.makeText(context, "Video saved", Toast.LENGTH_SHORT).show();
        if (Build.VERSION.SDK_INT >= 19) {
            MediaScannerConnection.scanFile(context, new String[]{newVid.getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                }
            });
        } else {
            context.sendBroadcast(new Intent("android.intent.action.MEDIA_MOUNTED", Uri.fromFile(newVid)));
        }
    } catch (Exception e) {
        ToastUtils.ErrorToast(context, "Error downloading video. Please try again");
    }
}
 
Example #7
Source File: Path.java    From SMP with GNU General Public License v3.0 6 votes vote down vote up
private static void scanMediaFiles(Context context, Collection<File> filesToScan) {
    String[] filesToScanArray = new String[filesToScan.size()];
    int i = 0;
    for (File file : filesToScan) {
        filesToScanArray[i] = file.getAbsolutePath();
        //if (filesToScanArray[i].contains("emulated/0"))
            Log.d("Settings", "fileToScan: " + filesToScanArray[i]);
        i++;
    }

    if (filesToScanArray.length != 0) {
        MediaScannerConnection.scanFile(context, filesToScanArray, null, null);
    } else {
        Log.e("Settings", "Media scan requested when nothing to scan");
    }
}
 
Example #8
Source File: RecorderService.java    From screenrecorder with GNU Affero General Public License v3.0 6 votes vote down vote up
private void indexFile() {
    //Create a new ArrayList and add the newly created video file path to it
    ArrayList<String> toBeScanned = new ArrayList<>();
    toBeScanned.add(SAVEPATH);
    String[] toBeScannedStr = new String[toBeScanned.size()];
    toBeScannedStr = toBeScanned.toArray(toBeScannedStr);

    //Request MediaScannerConnection to scan the new file and index it
    MediaScannerConnection.scanFile(this, toBeScannedStr, null, new MediaScannerConnection.OnScanCompletedListener() {

        @Override
        public void onScanCompleted(String path, Uri uri) {
            Log.i(Const.TAG, "SCAN COMPLETED: " + path);
            //Show toast on main thread
            Message message = mHandler.obtainMessage();
            message.sendToTarget();
            stopSelf();
        }
    });
}
 
Example #9
Source File: CameraActivity.java    From AndroidProject with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAMERA_REQUEST_CODE) {
        switch (resultCode) {
            case RESULT_OK:
                // 重新扫描多媒体(否则可能扫描不到)
                MediaScannerConnection.scanFile(getApplicationContext(), new String[]{mFile.getPath()}, null,null);
                break;
            case RESULT_CANCELED:
                // 删除这个文件
                mFile.delete();
                break;
            default:
                break;
        }
        setResult(resultCode);
        finish();
    }
}
 
Example #10
Source File: FileManagerActivity.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
private void refreshMediaResource(){
    // Android 4.4
    if(Build.VERSION.SDK_INT>= 19){
        MediaScannerConnection.scanFile(this, new String[]{Environment.getExternalStorageDirectory().getAbsolutePath()},
                null, new MediaScannerConnection.OnScanCompletedListener() {
                    public void onScanCompleted(String path, Uri uri) {


                    }
                }
        );
    }else{
        IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED);
        intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
        intentFilter.addDataScheme("file");
        scanReceiver = new ScanSdFilesReceiver();
        registerReceiver(scanReceiver, intentFilter);
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath())));
    }
}
 
Example #11
Source File: MediaScanner.java    From PlayMusicExporter with MIT License 6 votes vote down vote up
/**
 * Adds a file to the android media system
 * @param context The context of the app
 * @param string Path to the file
 */
public MediaScanner(Context context, String string) {
    mFile = string;

    // Connect the media scanner
    mMediaScanner = new MediaScannerConnection(context, this);
    mMediaScanner.connect();
}
 
Example #12
Source File: ModifyAvaterPresenter.java    From Android with MIT License 6 votes vote down vote up
@Override
public void start() {
    scanner = new MediaScannerConnection(mView.getActivity(), new MediaScannerConnection.MediaScannerConnectionClient() {
        @Override
        public void onMediaScannerConnected() {
            if(pathDcim != null){
                scanner.scanFile(pathDcim,"media*//*");
            }
        }

        @Override
        public void onScanCompleted(String path, Uri uri) {
            scanner.disconnect();
        }
    });
}
 
Example #13
Source File: QRGeneratorUtils.java    From privacy-friendly-qr-scanner with GNU General Public License v3.0 6 votes vote down vote up
public static void saveImageToExternalStorage(Context context, Bitmap finalBitmap) {
    File externalPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File myDir = new File(externalPath, "Generated QR-Codes");
    myDir.mkdirs();

    File file = writeToFile(myDir, finalBitmap);

    // Tell the media scanner about the new file so that it is
    // immediately available to the user.
    MediaScannerConnection.scanFile(context, new String[] { file.toString() }, null,
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                    Log.i("ExternalStorage", "Scanned " + path + ":");
                    Log.i("ExternalStorage", "-> uri=" + uri);
                }
            });
}
 
Example #14
Source File: PictureActivity.java    From Moment with GNU General Public License v3.0 6 votes vote down vote up
private void download() {
    Observable.just(null)
            .compose(bindToLifecycle())
            .compose(ensurePermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE))
            .filter(granted -> {
                if (granted) {
                    return true;
                } else {
                    Toasty.info(this, getString(R.string.permission_required),
                            Toast.LENGTH_LONG).show();
                    return false;
                }
            })
            .flatMap(granted -> ensureDirectory("Moment"))
            .map(file -> new File(file, makeFileName()))
            .flatMap(file -> file.exists()
                    ? Observable.just(file)
                    : save(file))
            .doOnNext(file -> MediaScannerConnection.scanFile(getApplicationContext(),
                    new String[]{file.getPath()}, null, null))
            .subscribe(file -> {
                showTips(getString(R.string.save_path_tips, file.getPath()));
            });
}
 
Example #15
Source File: SaveAttachmentTask.java    From Silence with GNU General Public License v3.0 6 votes vote down vote up
private boolean saveAttachment(Context context, MasterSecret masterSecret, Attachment attachment) throws IOException {
  String contentType      = MediaUtil.getCorrectedMimeType(attachment.contentType);
  File mediaFile          = constructOutputFile(contentType, attachment.date);
  InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, attachment.uri);

  if (inputStream == null) {
    return false;
  }

  OutputStream outputStream = new FileOutputStream(mediaFile);
  Util.copy(inputStream, outputStream);

  MediaScannerConnection.scanFile(context, new String[]{mediaFile.getAbsolutePath()},
                                  new String[]{contentType}, null);

  return true;
}
 
Example #16
Source File: AbstractUVCCameraHandler.java    From AndroidUSBCamera with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void handleUpdateMedia(final String path) {
    if (DEBUG) Log.v(TAG_THREAD, "handleUpdateMedia:path=" + path);
    final Activity parent = mWeakParent.get();
    final boolean released = (mHandler == null) || mHandler.mReleased;
    if (parent != null && parent.getApplicationContext() != null) {
        try {
            if (DEBUG) Log.i(TAG, "MediaScannerConnection#scanFile");
            MediaScannerConnection.scanFile(parent.getApplicationContext(), new String[]{path}, null, null);
        } catch (final Exception e) {
            Log.e(TAG, "handleUpdateMedia:", e);
        }
        if (released || parent.isDestroyed())
            handleRelease();
    } else {
        Log.w(TAG, "MainActivity already destroyed");
        // give up to add this movie to MediaStore now.
        // Seeing this movie on Gallery app etc. will take a lot of time.
        handleRelease();
    }
}
 
Example #17
Source File: FlickrUploaderActivity.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onRefresh() {
    if (medias != null) {
        String root = null;
        for (Media media : medias) {
            if (root == null) {
                root = media.getFolderPath();
            } else if (!media.getFolderPath().startsWith(root)) {
                while (root.length() > 1 && !media.getFolderPath().startsWith(root)) {
                    root = ToolString.getParentPath(root);
                }
                if (root.length() <= 1) {
                    break;
                }
            }
        }
        if (root != null) {
            LOG.debug("rescanning " + root);
            MediaScannerConnection.scanFile(getApplicationContext(), new String[]{root}, null, new OnScanCompletedListener() {
                @Override
                public void onScanCompleted(String path, Uri uri) {
                    LOG.debug("file " + path + " was scanned seccessfully: " + uri);
                    load(true);
                }
            });
        } else {
            load(true);
        }
    }
}
 
Example #18
Source File: CameraLauncher.java    From reader with MIT License 5 votes vote down vote up
private void scanForGallery(Uri newImage) {
    this.scanMe = newImage;
    if(this.conn != null) {
        this.conn.disconnect();
    }
    this.conn = new MediaScannerConnection(this.cordova.getActivity().getApplicationContext(), this);
    conn.connect();
}
 
Example #19
Source File: ContextUtils.java    From Stringlate with MIT License 5 votes vote down vote up
/**
 * Request the givens paths to be scanned by MediaScanner
 *
 * @param files Files and folders to scan
 */
public void mediaScannerScanFile(File... files) {
    if (android.os.Build.VERSION.SDK_INT > 19) {
        String[] paths = new String[files.length];
        for (int i = 0; i < files.length; i++) {
            paths[i] = files[i].getAbsolutePath();
        }
        MediaScannerConnection.scanFile(_context, paths, null, null);
    } else {
        for (File file : files) {
            _context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
        }
    }
}
 
Example #20
Source File: FileUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
public static void updateMediaStore(Context context, String... pathsArray){
    MediaScannerConnection.scanFile(context, pathsArray, null, new MediaScannerConnection.OnScanCompletedListener() {
        @Override
        public void onScanCompleted(String s, Uri uri) {
            //Log.i("Scanner", "Scanned " + s + ":");
            //Log.i("Scanner", "-> uri=" + uri);
        }
    });
}
 
Example #21
Source File: StoryFragment.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
private void saveImage(Bitmap bitmap) {
    File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + GlobalConstant.APP_NAME);
    if (!file.exists())
        file.mkdirs();

    String fileName = GlobalConstant.DOWNLOADED_FILENAME + System.currentTimeMillis() + ".jpg";

    File newImage = new File(file, fileName);
    if (newImage.exists()) file.delete();
    try {
        FileOutputStream out = new FileOutputStream(newImage);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();


        Downloads downloads = new Downloads();
        downloads.setUser_id("");
        downloads.setPath(file.getAbsolutePath() + "/" + fileName);
        downloads.setUsername("");
        downloads.setType(0);
        downloads.setFilename(fileName);
        dataObjectRepositry.addDownloadedData(downloads);

        Toast.makeText(getActivity(), "Saving image...", Toast.LENGTH_SHORT).show();

        if (Build.VERSION.SDK_INT >= 19) {
            MediaScannerConnection.scanFile(getActivity(), new String[]{newImage.getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                }
            });
        } else {
            getActivity().sendBroadcast(new Intent("android.intent.action.MEDIA_MOUNTED", Uri.fromFile(newImage)));
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #22
Source File: VideoStorageUtils.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * Notifies the MediaScanners after Downloading the Video, so it
 * is immediately available to the user.
 */
private static void notifyMediaScanners(Context context,
                                        File videoFile) {
    // Tell the media scanner about the new file so that it is
    // immediately available to the user.
    MediaScannerConnection.scanFile
        (context,
         new String[] { videoFile.toString() },
         null,
         new MediaScannerConnection.OnScanCompletedListener() {
             public void onScanCompleted(String path, 
                                         Uri uri) {
             }
         });
}
 
Example #23
Source File: StoryFragment.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
public void onDeleteClick(final File f) {


        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity());
        View view2 = layoutInflaterAndroid.inflate(R.layout.item_dialog, null);
        builder.setView(view2);
        builder.setCancelable(false);
        final AlertDialog alertDialog = builder.create();
        alertDialog.show();


        BoldTextView title = view2.findViewById(R.id.titleText);
        RegularTextView descriptionsText = view2.findViewById(R.id.descriptionText);
        title.setText("Delete");
        descriptionsText.setText("Are you sure you wanna delete this file?");

        view2.findViewById(R.id.yes).setOnClickListener(v1 -> {
            if (Build.VERSION.SDK_INT >= 19) {
                MediaScannerConnection.scanFile(getActivity(), new String[]{f.getAbsolutePath()}, null, new MediaScannerConnection.OnScanCompletedListener() {
                    public void onScanCompleted(String path, Uri uri) {
                    }
                });
            } else {
                getActivity().sendBroadcast(new Intent(Intent.ACTION_MEDIA_REMOVED, Uri.fromFile(f)));
            }

            f.delete();
            alertDialog.dismiss();

            storyListener.deletePage(true);

            if (context != null)
                ToastUtils.SuccessToast(context, "File deleted successfully");

        });
        view2.findViewById(R.id.no).setOnClickListener(v12 -> alertDialog.dismiss());


    }
 
Example #24
Source File: ExportPriActivity.java    From Android with MIT License 5 votes vote down vote up
@Override
public void initView() {
    mActivity = this;
    toolbarTop.setBlackStyle();
    toolbarTop.setTitle(null, R.string.Set_Backup_Private_Key);

    userBean = SharedPreferenceUtil.getInstance().getUser();
    userBean.setBack(true);
    SharedPreferenceUtil.getInstance().putUser(userBean);

    CreateScan createScan = new CreateScan();
    bitmap = createScan.generateQRCode(MemoryDataManager.getInstance().getPriKey(), getResources().getColor(R.color.color_ffffff));
    backupImg.setImageBitmap(bitmap);

    scanner = new MediaScannerConnection(mActivity, new MediaScannerConnection.MediaScannerConnectionClient() {
        @Override
        public void onMediaScannerConnected() {
            if(pathDcim != null){
                scanner.scanFile(pathDcim,"media/*");
            }
        }

        @Override
        public void onScanCompleted(String path, Uri uri) {
            scanner.disconnect();
        }
    });
}
 
Example #25
Source File: FileBackend.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public void updateMediaScanner(File file, final Runnable callback) {
    if (!isInDirectoryThatShouldNotBeScanned(mXmppConnectionService, file)) {
        MediaScannerConnection.scanFile(mXmppConnectionService, new String[]{file.getAbsolutePath()}, null, new MediaScannerConnection.MediaScannerConnectionClient() {
            @Override
            public void onMediaScannerConnected() {

            }

            @Override
            public void onScanCompleted(String path, Uri uri) {
                if (callback != null && file.getAbsolutePath().equals(path)) {
                    callback.run();
                } else {
                    Log.d(Config.LOGTAG, "media scanner scanned wrong file");
                    if (callback != null) {
                        callback.run();
                    }
                }
            }
        });
        return;
        /*Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        intent.setData(Uri.fromFile(file));
        mXmppConnectionService.sendBroadcast(intent);*/
    } else if (file.getAbsolutePath().startsWith(getAppMediaDirectory(mXmppConnectionService))) {
        createNoMedia(file.getParentFile());
    }
    if (callback != null) {
        callback.run();
    }
}
 
Example #26
Source File: ContextUtils.java    From kimai-android with MIT License 5 votes vote down vote up
/**
 * Request the givens paths to be scanned by MediaScanner
 *
 * @param files Files and folders to scan
 */
public void mediaScannerScanFile(File... files) {
    if (android.os.Build.VERSION.SDK_INT > 19) {
        String[] paths = new String[files.length];
        for (int i = 0; i < files.length; i++) {
            paths[i] = files[i].getAbsolutePath();
        }
        MediaScannerConnection.scanFile(_context, paths, null, null);
    } else {
        for (File file : files) {
            _context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
        }
    }
}
 
Example #27
Source File: FoldersFragment.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
private void scanPaths(@Nullable String[] toBeScanned) {
    if (getActivity() == null) return;
    if (toBeScanned == null || toBeScanned.length < 1) {
        Toast.makeText(getActivity(), R.string.nothing_to_scan, Toast.LENGTH_SHORT).show();
    } else {
        MediaScannerConnection.scanFile(getActivity().getApplicationContext(), toBeScanned, null, new UpdateToastMediaScannerCompletionListener(getActivity(), toBeScanned));
    }
}
 
Example #28
Source File: InformaCamMediaScanner.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
public InformaCamMediaScanner(Context context, File f, OnMediaScannedListener listener) {
	this.f = f;
	this.context = context;
	
	mListener = listener;
	msc = new MediaScannerConnection(this.context, this);
	msc.connect();
}
 
Example #29
Source File: MediaUtil.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
public static void notifySysMedia2Scan(Context context, MediaScannerConnection.OnScanCompletedListener callback, String toScanTheFilePath) {
    if (null == toScanTheFilePath) {
        toScanTheFilePath = Environment.getExternalStorageDirectory().getAbsolutePath();
    }
    if (!Util.isCompateApi(19)) {//android 4.4系统之前,发广播的方式通知系统去扫描
        context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://" + toScanTheFilePath)));
    }
    else{
        MediaScannerConnection.scanFile(context, new String[] {toScanTheFilePath}, null, callback);
    }
}
 
Example #30
Source File: ContextUtils.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Request the givens paths to be scanned by MediaScanner
 *
 * @param files Files and folders to scan
 */
public void mediaScannerScanFile(final File... files) {
    if (android.os.Build.VERSION.SDK_INT > 19) {
        String[] paths = new String[files.length];
        for (int i = 0; i < files.length; i++) {
            paths[i] = files[i].getAbsolutePath();
        }
        MediaScannerConnection.scanFile(_context, paths, null, null);
    } else {
        for (File file : files) {
            _context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
        }
    }
}