How to get the parameters of a Url on Android

Asked

Viewed 591 times

1

In the I have the following URL

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

I’d like to take the parameters of this URL how do I do it in a simple way?

1 answer

3

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

Do it this way:

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());
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.