public class

UriUtil

extends Object
java.lang.Object
   ↳ com.facebook.common.util.UriUtil

Summary

Constants
String DATA_SCHEME Data scheme for URIs
String HTTPS_SCHEME
String HTTP_SCHEME http scheme for URIs
String LOCAL_ASSET_SCHEME Asset scheme for URIs
String LOCAL_CONTENT_SCHEME Content URI scheme for URIs
String LOCAL_FILE_SCHEME File scheme for URIs
String LOCAL_RESOURCE_SCHEME Resource scheme for URIs
String QUALIFIED_RESOURCE_SCHEME Resource scheme for fully qualified resources which might have a package name that is different than the application one.
Public Constructors
UriUtil()
Public Methods
static AssetFileDescriptor getAssetFileDescriptor(ContentResolver contentResolver, Uri srcUri)
Gets the AssetFileDescriptor for a local file.
static String getRealPathFromUri(ContentResolver contentResolver, Uri srcUri)
Get the path of a file from the Uri.
static String getSchemeOrNull(Uri uri)
static Uri getUriForFile(File file)
Returns a URI for a given file using fromFile(File).
static Uri getUriForQualifiedResource(String packageName, int resourceId)
Returns a URI for the given resource ID in the given package.
static Uri getUriForResourceId(int resourceId)
Return a URI for the given resource ID.
static boolean isDataUri(Uri uri)
Check if the uri is a data uri
static boolean isLocalAssetUri(Uri uri)
Check if uri represents local asset
static boolean isLocalCameraUri(Uri uri)
Checks if the given URI is for a photo from the device's local media store.
static boolean isLocalContactUri(Uri uri)
Checks if the given URI is a general Contact URI, and not a specific display photo.
static boolean isLocalContentUri(Uri uri)
Check if uri represents local content
static boolean isLocalFileUri(Uri uri)
Check if uri represents local file
static boolean isLocalResourceUri(Uri uri)
Check if uri represents local resource
static boolean isNetworkUri(Uri uri)
Check if uri represents network resource
static boolean isQualifiedResourceUri(Uri uri)
Check if uri represents fully qualified resource URI.
static Uri parseUriOrNull(String uriAsString)
A wrapper around parse(String) that returns null if the input is null.
static URL uriToUrl(Uri uri)
Convert android.net.Uri to java.net.URL as necessary for some networking APIs.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String DATA_SCHEME

Data scheme for URIs

Constant Value: "data"

public static final String HTTPS_SCHEME

Constant Value: "https"

public static final String HTTP_SCHEME

http scheme for URIs

Constant Value: "http"

public static final String LOCAL_ASSET_SCHEME

Asset scheme for URIs

Constant Value: "asset"

public static final String LOCAL_CONTENT_SCHEME

Content URI scheme for URIs

Constant Value: "content"

public static final String LOCAL_FILE_SCHEME

File scheme for URIs

Constant Value: "file"

public static final String LOCAL_RESOURCE_SCHEME

Resource scheme for URIs

Constant Value: "res"

public static final String QUALIFIED_RESOURCE_SCHEME

Resource scheme for fully qualified resources which might have a package name that is different than the application one. This has the constant value of "android.resource".

Constant Value: "android.resource"

Public Constructors

public UriUtil ()

Public Methods

public static AssetFileDescriptor getAssetFileDescriptor (ContentResolver contentResolver, Uri srcUri)

Gets the AssetFileDescriptor for a local file. This offers an alternative solution for opening content:// scheme files

Parameters
contentResolver the content resolver which will query for the source file
srcUri The source uri
Returns
  • The AssetFileDescriptor for the file or null if it doesn't exist

public static String getRealPathFromUri (ContentResolver contentResolver, Uri srcUri)

Get the path of a file from the Uri.

Parameters
contentResolver the content resolver which will query for the source file
srcUri The source uri
Returns
  • The Path for the file or null if doesn't exists

public static String getSchemeOrNull (Uri uri)

Parameters
uri uri to extract scheme from, possibly null
Returns
  • null if uri is null, result of uri.getScheme() otherwise

public static Uri getUriForFile (File file)

Returns a URI for a given file using fromFile(File).

Parameters
file a file with a valid path
Returns
  • the URI

public static Uri getUriForQualifiedResource (String packageName, int resourceId)

Returns a URI for the given resource ID in the given package. Use this method only if you need to specify a package name different to your application's main package.

Parameters
packageName a package name (e.g. com.facebook.myapp.plugin)
resourceId to resource ID to use
Returns
  • the URI

public static Uri getUriForResourceId (int resourceId)

Return a URI for the given resource ID. The returned URI consists of a LOCAL_RESOURCE_SCHEME scheme and the resource ID as path.

Parameters
resourceId the resource ID to use
Returns
  • the URI

public static boolean isDataUri (Uri uri)

Check if the uri is a data uri

public static boolean isLocalAssetUri (Uri uri)

Check if uri represents local asset

Parameters
uri uri to check
Returns
  • true if uri's scheme is equal to "asset"

public static boolean isLocalCameraUri (Uri uri)

Checks if the given URI is for a photo from the device's local media store.

Parameters
uri the URI to check
Returns
  • true if the URI points to a media store photo

public static boolean isLocalContactUri (Uri uri)

Checks if the given URI is a general Contact URI, and not a specific display photo.

Parameters
uri the URI to check
Returns
  • true if the uri is a Contact URI, and is not already specifying a display photo.

public static boolean isLocalContentUri (Uri uri)

Check if uri represents local content

Parameters
uri uri to check
Returns
  • true if uri's scheme is equal to "content"

public static boolean isLocalFileUri (Uri uri)

Check if uri represents local file

Parameters
uri uri to check
Returns
  • true if uri's scheme is equal to "file"

public static boolean isLocalResourceUri (Uri uri)

Check if uri represents local resource

Parameters
uri uri to check
Returns

public static boolean isNetworkUri (Uri uri)

Check if uri represents network resource

Parameters
uri uri to check
Returns
  • true if uri's scheme is equal to "http" or "https"

public static boolean isQualifiedResourceUri (Uri uri)

Check if uri represents fully qualified resource URI.

Parameters
uri uri to check
Returns

public static Uri parseUriOrNull (String uriAsString)

A wrapper around parse(String) that returns null if the input is null.

Parameters
uriAsString the uri as a string
Returns
  • the parsed Uri or null if the input was null

public static URL uriToUrl (Uri uri)

Convert android.net.Uri to java.net.URL as necessary for some networking APIs.

Parameters
uri uri to convert
Returns
  • url pointing to the same resource as uri