public static String encodeQuery(String url){
  Uri uri=Uri.parse(url);
  try {
    String query=uri.getQuery();
    String encodedQuery=query != null ? URLEncoder.encode(query,"UTF-8") : null;
    URI tmp=new URI(uri.getScheme(),uri.getAuthority(),uri.getPath(),null,uri.getFragment());
    return tmp + (encodedQuery != null && encodedQuery.length() > 0 ? "?" + encodedQuery : "");
  }
 catch (  UnsupportedEncodingException ignore) {
  }
catch (  URISyntaxException ignore) {
  }
  return uri.toString();
}

public static String encodeQuery ( String url ) { Uri uri = Uri . parse ( url ) ; try { String query = uri . getQuery ( ) ; String encodedQuery = query != null ? URLEncoder . encode ( query , "UTF-8" ) : null ; URI tmp = new URI ( uri . getScheme ( ) , uri . getAuthority ( ) , uri . getPath ( ) , null , uri . getFragment ( ) ) ; return tmp + ( encodedQuery != null && encodedQuery . length ( ) > 0 ? "?" + encodedQuery : "" ) ; } catch ( UnsupportedEncodingException ignore ) { } catch ( URISyntaxException ignore ) { } return uri . toString ( ) ; }
this method encodes the query part of an url
