android.net.Uri.getHost() is a method used in Android development to extract the host name from a Uri object. This method returns a string that represents the host component of a URI.
Here are some examples of using android.net.Uri.getHost() in Java:
Example 1:
String uriString = "https://www.example.com/path/to/resource"; Uri uri = Uri.parse(uriString); String host = uri.getHost(); System.out.println("Host: " + host);
In this example, the Uri object is created using Uri.parse() and the string representation of the URI. The getHost() method is then called on the Uri object to extract the host name, which is then printed to the console.
Example 2:
Uri.Builder builder = new Uri.Builder(); builder.scheme("https") .authority("www.example.com") .appendPath("path") .appendPath("to") .appendPath("resource"); Uri uri = builder.build(); String host = uri.getHost(); System.out.println("Host: " + host);
In this example, the Uri object is created using Uri.Builder, which allows you to construct a URI by adding various components to it. The getHost() method is then called on the Uri object to extract the host name, which is then printed to the console.
Package Library:
android.net.Uri belongs to the Android SDK library.
Java Uri.getHost - 30 examples found. These are the top rated real world Java examples of android.net.Uri.getHost extracted from open source projects. You can rate examples to help us improve the quality of examples.