How to get parameters from a url in android and java

public static Map<String, String> getParametersFromUrl(String url)
 {
 Map<String, String> map = new HashMap<String, String>();

 if(url!=null && URLUtil.isValidUrl(url))
 {
 String[] params = url.split("[&,?]");
 for (String param : params)
 {
 try {
 String name = param.split("=")[0];
 String value = param.split("=")[1];
 map.put(name, value);
 } catch (Exception e)
 {
 Log.d("Error", "No value for parameter");
 }
 }
 }
 return map;
 }
Advertisements

About krishjlk

http://www.facebook.com/krishna.kanth.121

One response to “How to get parameters from a url in android and java”

  1. Zain says :

    Thanks for the solution

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: