Android Utililty Methods URL Parse

List of utility methods to do URL Parse

Description

The list of methods to do URL Parse are organized into topic(s).

Method

MapparseHttpParamsToHash(String s)
parse Http Params To Hash
HashMap hashmap = new HashMap();
String as[] = s.split("&");
int i = as.length;
for (int j = 0; j < i; j++) {
    String s1 = as[j];
    if (s1.indexOf("=") > 0) {
        String as1[] = s1.split("=");
        String s2 = as1[0];
...
StringgetHost(String url)
Will take a url such as http://www.stackoverflow.com and return www.stackoverflow.com Author: aioobe http://stackoverflow.com/a/4826122/1271424
if (url == null || url.length() == 0)
    return "";
int doubleslash = url.indexOf("//");
if (doubleslash == -1)
    doubleslash = 0;
else
    doubleslash += 2;
int end = url.indexOf('/', doubleslash);
...
StringgetNormalizedURLString(String url)
get Normalized URL String
if (url != null) {
    try {
        StringBuffer buffer = new StringBuffer();
        URI uri = new URI(url);
        String scheme = uri.getScheme().toLowerCase();
        buffer.append(scheme); 
        buffer.append("://");
        buffer.append(uri.getHost().toLowerCase()); 
...
StringgetOrigin(String url)
Get the origin of an url: Ex getOrigin("http://www.example.com:8080/index.html?bar=foo") would return "http://www.example.com:8080".
return nativeGetOrigin(url);
StringgetParentUrl(String url)
get Parent Url
int index = url.lastIndexOf("/");
if (index > 0)
    return url.substring(0, index);
return "";
StringgetRecentMediaUrl(String tag)
get Recent Media Url
return BASE_API_URL + "/tags/" + tag + "/media/recent?client_id="
        + INSTAGRAM_API_KEY;
StringgetStringFromUrl(String url)
get String From Url
HttpGet get = new HttpGet(url);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity, "UTF-8");
StringgetUrlContent(String urlStr)
get Url Content
HttpURLConnection urlConnection = null;
try {
    URL url = new URL(urlStr);
    urlConnection = (HttpURLConnection) url.openConnection();
    InputStream in = new BufferedInputStream(
            urlConnection.getInputStream());
    byte[] bytes = new byte[1024];
    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
...
BundlegetUrlQueryParameters(final String url)
get Url Query Parameters
final Bundle bundle = new Bundle();
final String[] separated = url.split("\\?");
if (separated.length > 1) {
    final String query = separated[1];
    final String[] params = query.split("&");
    for (final String param : params) {
        final String[] keyvalue = param.split("=");
        final String key = URLDecoder.decode(keyvalue[0]);
...
booleancheckStringIsUrl(String input)
check String Is Url
if (input == null)
    return false;
if (input.indexOf("tel://") == 0) {
    return true;
if (input.indexOf("mailto:") == 0 && input.contains("@")) {
    return true;
if (input.indexOf("wtai://") == 0) {
    return true;
Pattern pattern = Pattern
        .compile(
                "(^((https|http|ftp|rtsp|mms)?://)"
                        + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?"
                        + "(([0-9]{1,3}\\.){3}[0-9]{1,3}"
                        + "|"
                        + "([0-9a-z_!~*'()-]+\\.)*"
                        + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\\."
                        + "[a-z]{2,6})"
                        + "(:[0-9]{1,4})?"
                        + "((/?)|"
                        + "(/[0-9a-z\\u4e00-\\u9fa5_!~*'().;?:@&=+$,%#-/]+)+/?)$)|(^file://*)",
                Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(input.trim());
if (matcher.find()) {
    return true;
} else {
    return false;