add Get Parameter to URL - Android Network

Android examples for Network:URL

Description

add Get Parameter to URL

Demo Code


import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class Main{
    public static String addGetParameter(String s, String s1, String s2) {
        if (StringUtils.isNullOrEmpty(s2) || StringUtils.isNullOrEmpty(s1)
                || StringUtils.isNullOrEmpty(s)) {
            return s;
        }//from  w  w w .  j av  a 2s  .  c  o  m
        String s3;
        String s4;
        String s5;
        try {
            s3 = URLEncoder.encode(s2, "UTF-8");
            s4 = URLEncoder.encode(s1, "UTF-8");
        } catch (UnsupportedEncodingException unsupportedencodingexception) {
            return s;
        }
        if (s.contains("?")) {
            s5 = (new StringBuilder()).append(s).append("&").toString();
        } else {
            s5 = (new StringBuilder()).append(s).append("?").toString();
        }
        return (new StringBuilder()).append(s5).append(s4).append("=")
                .append(s3).toString();
    }
}

Related Tutorials