The android.net.Uri class contains a method called getAuthority() which returns the authority component of the URI. The authority typically consists of a hostname or IP address, followed by an optional port number separated by a colon. Here are some code examples using this method:
Example 1:
Uri uri = Uri.parse("https://www.example.com/path/file.txt"); String authority = uri.getAuthority(); System.out.println(authority); // prints "www.example.com"
In this example, we create a URI with a hostname of "www.example.com" and call the getAuthority() method to retrieve it.
Example 2:
Uri uri = Uri.parse("content://com.example.provider/table/1"); String authority = uri.getAuthority(); System.out.println(authority); // prints "com.example.provider"
This example shows how the getAuthority() method can be used to extract the authority from a content URI. In this case, the authority is the package name of the ContentProvider, which is "com.example.provider".
Package library: android.net
Java Uri.getAuthority - 30 examples found. These are the top rated real world Java examples of android.net.Uri.getAuthority extracted from open source projects. You can rate examples to help us improve the quality of examples.