Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I agree with foxter that the best choice is to get the code from the newest Android version and add to your codebase. Everytime I'm faced with issues like this, I create a method to abstract versions idiosyncrasies. It goes like this:</p> <pre><code>public class FWCompat { public static boolean isFroyo_8_OrNewer() { return Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.FROYO; } public static boolean isGingerbread_9_OrNewer() { return Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.GINGERBREAD; } public static boolean isHoneycomb_11_OrNewer() { return Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB; } public static boolean isHoneycomb_13_OrNewer() { return Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB_MR2; } public static boolean isJellyBean_16_OrNewer() { return Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.JELLY_BEAN; } } @SuppressLint("NewApi") public class FWUriCompat { public static Set&lt;String&gt; getQueryParameterNames(Uri uri) { if (FWCompat.isHoneycomb_11_OrNewer()) { return uri.getQueryParameterNames(); } return FW_getQueryParameterNames(uri); } private static Set&lt;String&gt; FW_getQueryParameterNames(Uri uri) { if (uri == null) { throw new InvalidParameterException("Can't get parameter from a null Uri"); } if (uri.isOpaque()) { throw new UnsupportedOperationException("This isn't a hierarchical URI."); } String query = uri.getEncodedQuery(); if (query == null) { return Collections.emptySet(); } Set&lt;String&gt; names = new LinkedHashSet&lt;String&gt;(); int start = 0; do { int next = query.indexOf('&amp;', start); int end = (next == -1) ? query.length() : next; int separator = query.indexOf('=', start); if (separator &gt; 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 &lt; query.length()); return Collections.unmodifiableSet(names); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload