public final class UriHelper
extends java.lang.Object
android.net.Uri
.Modifier and Type | Method and Description |
---|---|
static byte[] |
getBytesFromUri(Uri uri,
Context context)
Reads the contents of the resource pointed to by the Uri into a byte array.
|
static java.lang.String |
getFileExtension(Uri uri,
Context context) |
static java.lang.String |
getFilenameFromUri(Uri uri,
Context context)
Retrieves the filename of a Uri, if available.
|
static int |
getFileSizeFromUri(Uri uri,
Context context)
Retrieves the file size of a Uri, if available.
|
static java.lang.String |
getMimeType(Uri uri,
Context context) |
static java.lang.String |
getMimeTypeFromUrl(java.lang.String url) |
static boolean |
hasMimeType(Uri uri,
Context context,
java.lang.String mimeType) |
static boolean |
isUriInputStreamAvailable(Uri uri,
Context context)
Test whether an InputStream can be opened for the Uri.
|
public static byte[] getBytesFromUri(Uri uri, Context context) throws java.io.IOException
uri
- a Uri
pointing to a filecontext
- Android contextjava.io.IOException
- if there is an issue with the input stream from the Urijava.lang.IllegalStateException
- if null input stream was returned by the Context's Content
Resolverpublic static boolean isUriInputStreamAvailable(Uri uri, Context context)
uri
- a Uri
pointing to a filecontext
- Android contexttrue
if an InputStream can be opened for the Uripublic static java.lang.String getFilenameFromUri(Uri uri, Context context)
uri
- a Uri
pointing to a filecontext
- Android contextjava.lang.IllegalStateException
- if the Uri is not pointing to a file or the filename was not
availablepublic static int getFileSizeFromUri(Uri uri, Context context)
uri
- a Uri
pointing to a filecontext
- Android contextjava.lang.IllegalStateException
- if the Uri is not pointing to a file or the filesize was not
availablepublic static java.lang.String getMimeType(Uri uri, Context context)
public static java.lang.String getMimeTypeFromUrl(java.lang.String url)
public static java.lang.String getFileExtension(Uri uri, Context context)
public static boolean hasMimeType(Uri uri, Context context, java.lang.String mimeType)