get Query Value from URL - Android Network

Android examples for Network:URL

Description

get Query Value from URL

Demo Code


//package com.java2s;

import java.net.URL;

import java.util.HashMap;
import java.util.Map;

public class Main {
    public static String getQueryValue(String url, String name) {
        try {//from   w  w  w  .  j  av a 2s. c  o m
            URL dUrl = new URL("http://" + url);
            Map<String, String> query = getQueryMap(dUrl.getQuery());
            return query.get(name);

        } catch (Exception e) {
        }

        return null;
    }

    public static Map<String, String> getQueryMap(String query) {
        String[] params = query.split("&");
        Map<String, String> map = new HashMap<String, String>();
        for (String param : params) {
            String[] splitted = param.split("=");
            map.put(splitted[0], splitted[1]);
        }
        return map;
    }
}

Related Tutorials