Example usage for android.net Uri getEncodedQuery

List of usage examples for android.net Uri getEncodedQuery

Introduction

In this page you can find the example usage for android.net Uri getEncodedQuery.

Prototype

@Nullable
public abstract String getEncodedQuery();

Source Link

Document

Gets the encoded query component from this URI.

Usage

From source file:Main.java

public static Set<String> getQueryParameterNames(Uri uri) {
    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }//from   w  w w. j av  a2 s .com

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(uri.decode(name));

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}

From source file:Main.java

public static final HashMap<String, String> getAllRawQueryParameters(Intent intent) {
    HashMap<String, String> queries = new HashMap<String, String>();
    if (intent != null) {
        Uri uri = intent.getData();
        if (null != uri) {
            final String query = uri.getEncodedQuery();
            if (query != null) {
                final int length = query.length();
                int start = 0;
                do {
                    int nextAmpersand = query.indexOf('&', start);
                    int end = nextAmpersand != -1 ? nextAmpersand : length;

                    int separator = query.indexOf('=', start);
                    if (separator > end || separator == -1) {
                        separator = end;
                    }//  w w w. j  ava  2s  .c  om

                    String encodedKey = query.substring(start, separator);
                    String encodedValue = query.substring(separator + 1, end);

                    String key = Uri.decode(encodedKey);
                    if (!queries.containsKey(key)) {
                        queries.put(key, encodedValue);
                    }

                    // Move start to end of name.
                    if (nextAmpersand != -1) {
                        start = nextAmpersand + 1;
                    } else {
                        break;
                    }
                } while (true);
            }
        }
    }
    return queries;
}

From source file:net.reichholf.dreamdroid.intents.IntentFactory.java

public static Intent getStreamFileIntent(String fileName, String title) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    SimpleHttpClient shc = SimpleHttpClient.getInstance();
    ArrayList<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("file", fileName));
    Uri uri = Uri.parse(shc.buildFileStreamUrl(URIStore.FILE, params));
    Log.i(DreamDroid.LOG_TAG, "Streaming file: " + uri.getEncodedQuery());

    intent.setDataAndType(uri, "video/*");
    intent.putExtra("title", title);
    return intent;
}

From source file:Main.java

private static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException("This isn't a hierarchical URI.");
    }/*from w  w  w  .j a v  a 2 s  . com*/

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}

From source file:Main.java

public static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException("This isn't a hierarchical URI.");
    }//from   w ww. ja  va  2  s  . c  o m

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = next == -1 ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}

From source file:com.playhaven.android.data.DataCollectionField.java

/**
 * Unavailable in <11, so copied in. Difference is that names are not re-encoded in UTF-8. 
 * /*from  w w  w .j ava2 s . c om*/
 * Returns a set of the unique names of all query parameters. Iterating
 * over the set will return the names in order of their first occurrence.
 *
 * @throws UnsupportedOperationException if this isn't a hierarchical URI
 *
 * @return a set of decoded names
 */
public static Set<String> getQueryParameterNames(Uri uri) {

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(name);

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}

From source file:Main.java

public static final String getRawQueryParameter(Uri uri, String queryParameterName) {
    String ret = null;/*ww w .j  a va  2  s.co m*/

    if ((uri != null) && (!TextUtils.isEmpty(queryParameterName))) {
        final String query = uri.getEncodedQuery();
        if (query == null) {
            return null;
        }

        final String encodedKey = Uri.encode(queryParameterName, null);
        final int length = query.length();
        int start = 0;
        do {
            int nextAmpersand = query.indexOf('&', start);
            int end = nextAmpersand != -1 ? nextAmpersand : length;

            int separator = query.indexOf('=', start);
            if (separator > end || separator == -1) {
                separator = end;
            }

            if (separator - start == encodedKey.length()
                    && query.regionMatches(start, encodedKey, 0, encodedKey.length())) {
                if (separator == end) {
                    ret = "";
                } else {
                    ret = query.substring(separator + 1, end);
                }
                break;
            }

            // Move start to end of name.
            if (nextAmpersand != -1) {
                start = nextAmpersand + 1;
            } else {
                break;
            }
        } while (true);
    }

    return ret;
}

From source file:org.mobiledeeplinking.android.DeeplinkMatcher.java

public static Map<String, String> match(String route, JSONObject routeOptions,
        Map<String, String> routeParameters, Uri deeplink) throws JSONException {
    Map<String, String> results = new HashMap<String, String>(routeParameters);
    results = matchPathParameters(route, routeOptions, deeplink, results);
    if (results == null) {
        return null;
    }/*from   ww w.  j  a  va  2s .  c o m*/
    results = matchQueryParameters(routeOptions, deeplink.getEncodedQuery(), results);
    if (results == null) {
        return null;
    }

    if (checkForRequiredRouteParameters(routeOptions, results)) {
        return results;
    }

    return null;
}

From source file:com.oakesville.mythling.util.MediaStreamProxy.java

public static URL getNetUrl(Uri mediaUri) throws MalformedURLException {
    String netUrl = mediaUri.getScheme() + "://" + mediaUri.getHost() + ":" + mediaUri.getPort();
    netUrl += mediaUri.getPath();/*from   ww  w  . jav a2 s .  com*/
    if (mediaUri.getQuery() != null)
        netUrl += "?" + mediaUri.getEncodedQuery();
    return new URL(netUrl);
}

From source file:org.lol.reddit.common.General.java

public static Set<String> getUriQueryParameterNames(final Uri uri) {

    if (uri.isOpaque()) {
        throw new UnsupportedOperationException("This isn't a hierarchical URI.");
    }//from   w  ww.ja  v a  2  s .  c  om

    final String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    final Set<String> names = new LinkedHashSet<String>();
    int pos = 0;
    while (pos < query.length()) {
        int next = query.indexOf('&', pos);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', pos);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(pos, separator);
        names.add(Uri.decode(name));

        // Move start to end of name.
        pos = end + 1;
    }

    return Collections.unmodifiableSet(names);
}