Note that on Android, Uris are different from Java URIs. Here's how to avoid using hardcoded strings and at the same time create a Uri with only part of the string path of the http URL encoded in accordance with RFC2396:
Example URL string:
String thisUrl = "http://lapi.transitchicago.com/api/1.0/ttarrivals.aspx?key=[redacted]&mapid=value"
method:
private Uri.Builder builder; public Uri getUriFromUrl(String thisUrl) { URL url = new URL(thisUrl); builder = new Uri.Builder() .scheme(url.getProtocol()) .authority(url.getAuthority()) .appendPath(url.getPath()); return builder.build(); }
To handle query strings, you need to parse url.getQuery () as described here , and then pass this to the constructor. appendQueryParameter ().
Phileo99 Feb 27 '14 at 5:17 2014-02-27 05:17
source share