Code example for MediaScannerConnection

Methods: disconnect, scanFile

0
 
    @Override 
    public void onMediaScannerConnected() { 
        try{ 
            //set sec param to null cause jps is a not recognized mimetype or file will not added 
            scanner.scanFile(imgpath, null);
        } 
        catch (java.lang.IllegalStateException e)
        { 
            Log.e("MediaSCanner ERROR", e.getMessage());
            scanner.disconnect();
        } 
    } 
 
    @Override 
    public void onScanCompleted(String path, Uri uri) {
        scanner.disconnect();
    } 
}