Code example for MediaScannerConnection

Methods: connect, scanFile

0
		//check this file has scanned or not 
		SDAudio audio = getAudioByPath(uri.getPath());
		//this file has not scanned yet 
		if (audio == null) {
			try { 
				final MediaScannerConnection msc = new MediaScannerConnection(_context, new MediaScannerConnection.MediaScannerConnectionClient() {
					@Override 
					public void onScanCompleted(String path, Uri uri) {
						SDLibrary.this.notify();
					} 
					@Override 
					public void onMediaScannerConnected() { 
						SDLibrary.this.notify();
					} 
				}); 
				msc.connect();
				wait();
				msc.scanFile(uri.getPath(), "audio/mpeg");
				wait();
				audio = getAudioByPath(uri.getPath());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}