private Uri moveSrcToAuxIfNeeded(Uri srcUri,File dstFile){
  File srcFile=getLocalFileFromUri(mContext,srcUri);
  if (srcFile == null) {
    Log.d(LOGTAG,"Source file is not a local file, no update.");
    return srcUri;
  }
  File auxDiretory=getLocalAuxDirectory(dstFile);
  if (!auxDiretory.exists()) {
    boolean success=auxDiretory.mkdirs();
    if (!success) {
      return srcUri;
    }
  }
  File noMedia=new File(auxDiretory,".nomedia");
  if (!noMedia.exists()) {
    try {
      noMedia.createNewFile();
    }
 catch (    IOException e) {
      Log.e(LOGTAG,"Can't create the nomedia");
      return srcUri;
    }
  }
  File newSrcFile=new File(auxDiretory,dstFile.getName());
  String to=newSrcFile.getName();
  String from=srcFile.getName();
  to=to.substring(to.lastIndexOf("."));
  from=from.substring(from.lastIndexOf("."));
  if (!to.equals(from)) {
    String name=dstFile.getName();
    name=name.substring(0,name.lastIndexOf(".")) + from;
    newSrcFile=new File(auxDiretory,name);
  }
  if (!newSrcFile.exists()) {
    boolean success=srcFile.renameTo(newSrcFile);
    if (!success) {
      return srcUri;
    }
  }
  return Uri.fromFile(newSrcFile);
}

private Uri moveSrcToAuxIfNeeded ( Uri srcUri , File dstFile ) { File srcFile = getLocalFileFromUri ( mContext , srcUri ) ; if ( srcFile == null ) { Log . d ( LOGTAG , "Source file is not a local file, no update." ) ; return srcUri ; } File auxDiretory = getLocalAuxDirectory ( dstFile ) ; if ( ! auxDiretory . exists ( ) ) { boolean success = auxDiretory . mkdirs ( ) ; if ( ! success ) { return srcUri ; } } File noMedia = new File ( auxDiretory , ".nomedia" ) ; if ( ! noMedia . exists ( ) ) { try { noMedia . createNewFile ( ) ; } catch ( IOException e ) { Log . e ( LOGTAG , "Can't create the nomedia" ) ; return srcUri ; } } File newSrcFile = new File ( auxDiretory , dstFile . getName ( ) ) ; String to = newSrcFile . getName ( ) ; String from = srcFile . getName ( ) ; to = to . substring ( to . lastIndexOf ( "." ) ) ; from = from . substring ( from . lastIndexOf ( "." ) ) ; if ( ! to . equals ( from ) ) { String name = dstFile . getName ( ) ; name = name . substring ( 0 , name . lastIndexOf ( "." ) ) + from ; newSrcFile = new File ( auxDiretory , name ) ; } if ( ! newSrcFile . exists ( ) ) { boolean success = srcFile . renameTo ( newSrcFile ) ; if ( ! success ) { return srcUri ; } } return Uri . fromFile ( newSrcFile ) ; }
move the source file to auxiliary directory if needed and return the uri pointing to this new source file . if any file error happens , then just don ' t move into the auxiliary directory .
