Java.Net.URI Class
A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by .

See Also: URI Members

Syntax

[Android.Runtime.Register("java/net/URI", DoNotGenerateAcw=true)]
public sealed class URI : Java.Lang.Object, Java.IO.ISerializable, Java.Lang.IComparable, IDisposable

Remarks

A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by .

Parts of a URI

A URI is composed of many parts. This class can both parse URI strings into parts and compose URI strings from parts. For example, consider the parts of this URI: http://username:password@host:8080/directory/file?query#fragment
Component Example value Also known as
URI.Schemehttpprotocol
URI.SchemeSpecificPart//username:password@host:8080/directory/file?query#fragment
URI.Authorityusername:password@host:8080
URI.UserInfousername:password
URI.Hosthost
URI.Port8080
URI.Path/directory/file
URI.Queryquery
URI.Fragmentfragmentref

Absolute vs. Relative URIs

URIs are either URI.IsAbsolute.

Absolute URIs always have a scheme. If its scheme is supported by Java.Net.URL, you can use URI.ToURL to convert an absolute URI to a URL.

Relative URIs do not have a scheme and cannot be converted to URLs. If you have the absolute URI that a relative URI is relative to, you can use URI.Resolve(string) to compute the referenced absolute URI. Symmetrically, you can use URI.Relativize(URI) to compute the relative URI from one URI to another.

java Example

URI absolute = new URI("http://android.com/");
   URI relative = new URI("robots.txt");
   URI resolved = new URI("http://android.com/robots.txt");

   // print "http://android.com/robots.txt"
   System.out.println(absolute.resolve(relative));

   // print "robots.txt"
   System.out.println(absolute.relativize(resolved));
 

Opaque vs. Hierarchical URIs

Absolute URIs are either URI.IsOpaque. Relative URIs are always hierarchical.

Opaque URIs have both a scheme and a scheme-specific part that does not begin with the slash character: /. The contents of the scheme-specific part of an opaque URI is not parsed so an opaque URI never has an authority, user info, host, port, path or query. An opaque URIs may have a fragment, however. A typical opaque URI is mailto:robots@example.com.
Component Example value
Scheme mailto
Scheme-specific partrobots@example.com
Fragment

Hierarchical URIs may have values for any URL component. They always have a non-null path, though that path may be the empty string.

Encoding and Decoding URI Components

Each component of a URI permits a limited set of legal characters. Other characters must first be encoded before they can be embedded in a URI. To recover the original characters from a URI, they may be decoded. Contrary to what you might expect, this class uses the term raw to refer to encoded strings. The non-raw accessors return decoded strings. For example, consider how this URI is decoded: http://user:pa55w%3Frd@host:80/doc%7Csearch?q=green%20robots#over%206%22
Component Legal Characters Other Constraints Raw Value Value
Scheme 0-9, a-z, A-Z, +-.First character must be in a-z, A-Zhttp
Scheme-specific part0-9, a-z, A-Z, _-!.~'()*,;:$&+=?/[]@Non-ASCII characters okay //user:pa55w%3Frd@host:80/doc%7Csearch?q=green%20robots//user:pa55w?rd@host:80/doc|search?q=green robots
Authority 0-9, a-z, A-Z, _-!.~'()*,;:$&+=@[]Non-ASCII characters okay user:pa55w%3Frd@host:80user:pa55w?rd@host:80
User Info 0-9, a-z, A-Z, _-!.~'()*,;:$&+=Non-ASCII characters okay user:pa55w%3Frduser:pa55w?rd
Host 0-9, a-z, A-Z, -.[]Domain name, IPv4 address or [IPv6 address] host
Port 0-980
Path 0-9, a-z, A-Z, _-!.~'()*,;:$&+=/@Non-ASCII characters okay /doc%7Csearch/doc|search
Query 0-9, a-z, A-Z, _-!.~'()*,;:$&+=?/[]@Non-ASCII characters okay q=green%20robotsq=green robots
Fragment 0-9, a-z, A-Z, _-!.~'()*,;:$&+=?/[]@Non-ASCII characters okay over%206%22over 6"
A URI's host, port and scheme are not eligible for encoding and must not contain illegal characters.

To encode a URI, invoke any of the multiple-parameter constructors of this class. These constructors accept your original strings and encode them into their raw form.

To decode a URI, invoke the single-string constructor, and then use the appropriate accessor methods to get the decoded components.

The Java.Net.URL class can be used to retrieve resources by their URI.

[Android Documentation]

Requirements

Namespace: Java.Net
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1