Code example for MediaScannerConnection

Methods: scanFile

0
		msc.connect();
	} 
	 
	@Override 
	public void onMediaScannerConnected() { 
		msc.scanFile(f.getAbsolutePath(), null);
	} 
 
	@Override 
	public void onScanCompleted(String path, Uri uri) {
		((OnMediaScannedListener) a).onMediaScanned(uri);
	} 
	 
	public static Uri getUriFromFile(Context context, File file) {
		Uri uri = null;
		 
		ContentResolver cr = context.getContentResolver();
		Cursor c = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] {BaseColumns._ID}, MediaStore.Images.Media.DATA + "=?", new String[] {file.getAbsolutePath()}, null);
		if(c != null && c.moveToFirst()) {
			uri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, String.valueOf(c.getLong(c.getColumnIndex(BaseColumns._ID))));
			c.close();