How to get parameters from a url on Android

1

In the I have the following URL

String url = "http://domain.com/page?parameter1=value1&parameter2=value2";

I would like to get the parameters of this URL how do I do this in a simple way?

    
asked by anonymous 24.03.2014 / 22:04

1 answer

3

To do this you can use the class URLEncodedUtils which is a utility class of for URL 's

Do as follows:

String url = "http://domain.com/page?parameter1=value1&parameter2=value2";
 List<NameValuePair> parameters = URLEncodedUtils.parse(new URI(url),"utf-8");
for (NameValuePair p : parameters) {
    System.out.println(p.getName());
    System.out.println(p.getValue());
}
    
24.03.2014 / 22:04