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

/**
 * @return True if Uri is a MediaStore Uri.
 * @author paulburke//from   w  ww .j ava2s  .c o  m
 */
public static boolean isMediaUri(Uri uri) {
    return "media".equalsIgnoreCase(uri.getAuthority());
}

From source file:Main.java

/**
 * @param uri The Uri to check.//from  w w  w.  j  av a 2s. c  o m
 * @return Whether the Uri authority is DriveDocument.
 */
public static boolean isDriveDocument(Uri uri) {
    return "com.google.android.apps.docs.storage".equals(uri.getAuthority());
}

From source file:Main.java

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

From source file:Main.java

/**
 * @param uri The Uri to check./*from   w w  w .ja  va  2  s.com*/
 * @return Whether the Uri authority is OneDriveStorageProvider.
 */
private static boolean isOneDriveStorageDocument(Uri uri) {
    return "com.microsoft.skydrive.content.external".equals(uri.getAuthority());
}

From source file:Main.java

public static boolean isNewGooglePhotosUri(Uri uri) {
    return "com.google.android.apps.photos.contentprovider".equals(uri.getAuthority());
}

From source file:Main.java

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

From source file:Main.java

/**
 * @param uri The Uri to check.//from  ww w. j a v  a2  s  .  com
 * @return Whether the Uri authority is GoogleDriveLegacyStorageProvider.
 */
private static boolean isGoogleDriveLegacyStorageDocument(Uri uri) {
    return "com.google.android.apps.docs.storage.legacy".equals(uri.getAuthority());
}

From source file:Main.java

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

From source file:Main.java

/**
 * @return {@code uri} as-is if the authority is of contacts provider.  Otherwise
 * or {@code uri} is null, return null otherwise
 *///  w  w  w .  ja  v  a  2s . c  o m
public static Uri nullForNonContactsUri(Uri uri) {
    if (uri == null) {
        return null;
    }
    return ContactsContract.AUTHORITY.equals(uri.getAuthority()) ? uri : null;
}

From source file:Main.java

/**
 *
 * @param baseURL/* w  ww .j a  v  a  2  s  .c o m*/
 * @param key
 * @return the soundcloud track id
 */
public static String parseSoundCloud(String baseURL) {

    Uri parsed = Uri.parse(baseURL);
    String authority = parsed.getAuthority();
    String trackURL = null;
    if (TextUtils.isEmpty(authority)) {
        return null;
    }
    if (authority.indexOf("api.soundcloud") >= 0) {
        trackURL = baseURL;
    } else if (authority.indexOf("soundcloud") >= 0) {
        Uri parsedURI = Uri.parse(baseURL);
        try {
            trackURL = parsedURI.getQueryParameter("url");
        } catch (Exception exc) {

        }
    }

    if (TextUtils.isEmpty(trackURL) == true) {
        return null;
    }

    Uri base = Uri.parse(trackURL);

    List<String> segments = base.getPathSegments();
    for (String segment : segments) {
        if (TextUtils.isDigitsOnly(segment) == true) {
            return segment;// String.format("https://api.soundcloud.com/tracks/%1$s/stream?consumer_key=%2$s",segment,key);
        }
    }

    return "";
}