java - Extract parameter values from url android -
public static hashtable parseurlstring(string url) { hashtable parameter = new hashtable(); list<namevaluepair> params = null; try { params = urlencodedutils.parse(new uri(url), "utf-8"); (namevaluepair param : params) { if (param.getname() != null && param.getvalue() != null) parameter.put(param.getname(), param.getvalue()); } } catch (urisyntaxexception e) { e.printstacktrace(); } return parameter; }
the above method works me extract parameter name value hashtable in api 21+ namevaluepair , urlencodedutils deprecated best way can replace method?
in android, should never use urlencodedutils deprecated. alternative use uri class instead: retrieve query parameter keys using getqueryparameternames()
iterate on them , retrieve each value using getqueryparameter()
.
Comments
Post a Comment