Example usage for android.net Uri getAuthority

List of usage examples for android.net Uri getAuthority

Introduction

In this page you can find the example usage for android.net Uri getAuthority.

Prototype

@Nullable
public abstract String getAuthority();

Source Link

Document

Gets the decoded authority part of this URI.

Usage

From source file:Main.java

/**
 * @param uri//from   www  .ja v  a  2  s.c  om
 *            The Uri to check.
 * @return Whether the Uri authority is ExternalStorageProvider.
 * @author paulburke
 */
public static boolean isExternalStorageDocument(Uri uri) {
    return "com.android.externalstorage.documents".equals(uri.getAuthority());
}

From source file:Main.java

/**
 * @param uri/*from w  w  w  .ja  va2  s  .  c  o  m*/
 *            The Uri to check.
 * @return Whether the Uri authority is MediaProvider.
 * @author paulburke
 */
public static boolean isMediaDocument(Uri uri) {
    return "com.android.providers.media.documents".equals(uri.getAuthority());
}

From source file:Main.java

/**
 * @param uri/*from   ww  w.ja v  a 2s.  c o m*/
 *            The Uri to check.
 * @return Whether the Uri authority is Google Photos.
 */
public static boolean isGooglePhotosUri(Uri uri) {
    return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}

From source file:Main.java

/**
 * @param uri//  w ww  .j  a  v  a 2 s.  c o  m
 *            The Uri to check.
 * @return Whether the Uri authority is DownloadsProvider.
 * @author paulburke
 */
public static boolean isDownloadsDocument(Uri uri) {
    return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}

From source file:Main.java

/**
 * Transforms the given Uri and returns a Lookup-Uri that represents the contact.
 * For legacy contacts, a raw-contact lookup is performed. An {@link IllegalArgumentException}
 * can be thrown if the URI is null or the authority is not recognized.
 *
 * Do not call from the UI thread./*from   w  w w . ja  va  2  s. c  o m*/
 */
@SuppressWarnings("deprecation")
public static Uri ensureIsContactUri(final ContentResolver resolver, final Uri uri)
        throws IllegalArgumentException {
    if (uri == null)
        throw new IllegalArgumentException("uri must not be null");

    final String authority = uri.getAuthority();

    // Current Style Uri?
    if (ContactsContract.AUTHORITY.equals(authority)) {
        final String type = resolver.getType(uri);
        // Contact-Uri? Good, return it
        if (ContactsContract.Contacts.CONTENT_ITEM_TYPE.equals(type)) {
            return uri;
        }

        // RawContact-Uri? Transform it to ContactUri
        if (RawContacts.CONTENT_ITEM_TYPE.equals(type)) {
            final long rawContactId = ContentUris.parseId(uri);
            return RawContacts.getContactLookupUri(resolver,
                    ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
        }

        // Anything else? We don't know what this is
        throw new IllegalArgumentException("uri format is unknown");
    }

    // Legacy Style? Convert to RawContact
    final String OBSOLETE_AUTHORITY = Contacts.AUTHORITY;
    if (OBSOLETE_AUTHORITY.equals(authority)) {
        // Legacy Format. Convert to RawContact-Uri and then lookup the contact
        final long rawContactId = ContentUris.parseId(uri);
        return RawContacts.getContactLookupUri(resolver,
                ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId));
    }

    throw new IllegalArgumentException("uri authority is unknown");
}

From source file:sharedcode.turboeditor.util.AccessStorageApi.java

/**
 * @param uri The Uri to check./* www  .j a  va  2 s.  co m*/
 * @return Whether the Uri authority is Turbo Storage.
 */
public static boolean isTurboDocument(Uri uri) {
    return "sharedcode.turboeditor.util.documents".equals(uri.getAuthority());
}

From source file:Main.java

private static boolean isMediaUri(Uri uri) {
    return uri != null && ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())
            && MediaStore.AUTHORITY.equals(uri.getAuthority());
}

From source file:com.maskyn.fileeditorpro.util.AccessStorageApi.java

/**
 * @param uri The Uri to check.//from w  ww.  j av a 2s . c  o m
 * @return Whether the Uri authority is Turbo Storage.
 */
public static boolean isTurboDocument(Uri uri) {
    return "com.maskyn.fileeditorpro.util.documents".equals(uri.getAuthority());
}

From source file:Main.java

@SuppressLint("NewApi")
public static String getRealPath(Context context, Uri uri) {
    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        if (URI_EXTERNAL_DOCUMENTS.equals(uri.getAuthority())) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }//from   w ww.  j av  a 2  s .  c o  m
        } else if (URI_DOWNLOAD_DOCUMENTS.equals(uri.getAuthority())) {
            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
                    Long.valueOf(id));
            return getDataColumn(context, contentUri, null, null);
        } else if (URI_MEDIA_DOCUMENTS.equals(uri.getAuthority())) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }
            final String selection = "_id=?";
            final String[] selectionArgs = new String[] { split[1] };
            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        if (URI_GOOGLE_PHOTOS.equals(uri.getAuthority()))
            return uri.getLastPathSegment();
        return getDataColumn(context, uri, null, null);
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }
    return null;
}

From source file:dev.nick.app.screencast.camera.MediaScratchFileProvider.java

public static boolean isMediaScratchSpaceUri(final Uri uri) {
    if (uri == null) {
        return false;
    }/*from  w  w w . j  a  va2  s  .c  o m*/

    final List<String> segments = uri.getPathSegments();
    return (TextUtils.equals(uri.getScheme(), ContentResolver.SCHEME_CONTENT)
            && TextUtils.equals(uri.getAuthority(), AUTHORITY) && segments.size() == 1
            && isValidFileId(segments.get(0)));
}