Android Utililty Methods URL Create

List of utility methods to do URL Create

Description

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

Method

StringgenerateQueryJson(Map params)
generate Query Json
if (params == null || params.isEmpty())
    return "";
JSONObject aJsonObject = new JSONObject(params);
return aJsonObject.toString();
StringgenerateQueryString(Map params)
generate Query String
if (params == null)
    return "";
String aQueryParam = "";
if (params.size() > 0) {
    Set<String> aKeySet = params.keySet();
    Iterator<String> aKeyIterator = aKeySet.iterator();
    while (aKeyIterator.hasNext()) {
        String aParamName = aKeyIterator.next();
...
StringmapToQueryString( HashMap queryString)
map To Query String
StringBuilder sb = new StringBuilder();
try {
    for (HashMap.Entry<String, String> e : queryString.entrySet()) {
        if (sb.length() > 0) {
            sb.append('&');
        sb.append(URLEncoder.encode(e.getKey(), "UTF-8"))
                .append('=')
...
MapbuildQueries(String baseQuery, List datesByQueryIndex)
build Queries
Map<String, String> fqlByQueryIndex = new LinkedHashMap<String, String>();
for (int queryIndex = 0; queryIndex < datesByQueryIndex.size(); queryIndex++) {
    Date d = datesByQueryIndex.get(queryIndex);
    String query = baseQuery + convertToUnixTimeOneDayLater(d);
    fqlByQueryIndex.put(String.valueOf(queryIndex), query);
return fqlByQueryIndex;
UribuildEmailUri(String email, String subject, CharSequence body)
To be used with android.content.Intent.ACTION_SENDTO to send email, either in plain text or HTML.
StringBuilder builder = new StringBuilder();
builder.append("mailto:").append(email);
builder.append("?subject=").append(subject);
builder.append("&body=").append(body);
String uriText = builder.toString().replace(" ", "%20");
return Uri.parse(uriText);
Stringurl(String baseUrl, String relativePath)
url
if (relativePath == null || relativePath.length() == 0) {
    return relativePath;
if (relativePath.contains("://")
        || relativePath.matches("(?s)^[a-zA-Z][a-zA-Z0-9+-.]*:.*$")) { 
    return relativePath;
if (relativePath.charAt(0) == '/') {
...
Stringurl(String baseUrl, String relativePath)
url
if (relativePath == null || relativePath.length() == 0) {
    return relativePath;
if (relativePath.contains("://")) {
    return relativePath;
if (relativePath.charAt(0) == '/') {
    int index = baseUrl.indexOf("://");
...
StringcreateUrl(final String rootUrl, final String indivisualHost, final String featurePath, final int index, List pairs)
create Url
Uri.Builder builder = new Uri.Builder();
try {
    URI uri = new URI(rootUrl);
    String urlQuery = createQueryUrl(indivisualHost, featurePath,
            index, pairs);
    builder.scheme(uri.getScheme());
    builder.authority(uri.getAuthority());
    builder.path(uri.getPath() + "/");
...
StringbuildBodyParameterString( List> parameters)
Shorthand for building a parameter string used in the body of POST requests
return buildParameterString(parameters, ",", true);
StringbuildParameterString( List> parameters, String delimiter, boolean quote)
Builds a parameter string based on the given parameters, separated by given delimiter, and optionally quoted values
if (parameters == null || parameters.isEmpty())
    return "";
StringBuilder builder = new StringBuilder();
for (int i = 0; i < parameters.size(); i++) {
    String key = parameters.get(i).first;
    String value = parameters.get(i).second;
    if (value == null)
        continue;
...