Search code examples
phpandroidurlencodeurl-encoding

rawurlencode equivalent in Android


The rawurlencode($string) function in my PHP code string returns a string. I need the same string when encoding from android. I have used the following code:

encoded_url = URLEncoder.encode(string,"UTF-8");

The result from both android and php are almost same but the result from android has %0A attached at the end. I searched for it and found that %0A is linefeed. How do i remove this or is there a better equivalent of rawurlencode()?


Solution

  • Use encodeUri

     public static String encodeUri(String uri,
                                       String encoding)
                                throws UnsupportedEncodingException
        Encodes the given source URI into an encoded String. All various URI components are encoded according to their respective valid character sets.
        Parameters:
        uri - the URI to be encoded
        encoding - the character encoding to encode to
        Returns:
        the encoded URI
        Throws:
        IllegalArgumentException - when the given uri parameter is not a valid URI
        UnsupportedEncodingException - when the given encoding parameter is not supported