public static String getFilenameFromHeader(String url, String contentDisposition) {
    String filename;
    if (!TextUtils.isEmpty(contentDisposition)) {
      int index = contentDisposition.indexOf("filename");
      if (index > 0) {
        filename = contentDisposition.substring(index + 9, contentDisposition.length());
        return filename;
      } else {
        filename = getFilenameFromUrl(url);
      }
    } else {
      filename = getFilenameFromUrl(url);
    }

    try {
      filename = URLDecoder.decode(filename, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      /* ignore */
    }

    return filename;
  }
public static String getFilenameFromHeader ( String url , String contentDisposition ) { String filename ; if ( ! TextUtils . isEmpty ( contentDisposition ) ) { int index = contentDisposition . indexOf ( "filename" ) ; if ( index > 0 ) { filename = contentDisposition . substring ( index + 9 , contentDisposition . length ( ) ) ; return filename ; } else { filename = getFilenameFromUrl ( url ) ; } } else { filename = getFilenameFromUrl ( url ) ; } try { filename = URLDecoder . decode ( filename , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { } return filename ; }
Get filename from content disposition in header.

@param url url of current file to download
@param contentDisposition content disposition in header
@return filename in header if existed, otherwise get from url