Home » Android » java – What is the difference between URI and Uri class

java – What is the difference between URI and Uri class

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am confused , how to use Uri because i am using it in android development at Intent's Action dial

Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-2368"));

What I want to do :

I want to create a file inside which I want to put 2 phone numbers. Then, I want to use toUri() method with this file, and want to put that Uri in the intent, then I want to see what happens with the intent.

How to&Answers:

According to the Android API docs you can create a file Uri with:

public static Uri fromFile (File file)

Answer:

java.net.URI is mutable

android.net.Uri is immutable

java.net.URI

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

android.net.Uri
. A URI reference includes a URI and a fragment, the component of the URI following a ‘#’. Builds and parses URI references which conform to RFC 2396.

In the interest of performance, this class performs little to no validation. Behavior is undefined for invalid input. This class is very forgiving–in the face of invalid input, it will return garbage rather than throw an exception unless otherwise specified.

Answer:

URIs identify and URLs locate; however, locations are also identifications,
so every URL is also a URI, but there are URIs which are not URLs.

URL – http://example.com/some/page.html

URI – /some/page.html