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:com.android.messaging.datamodel.MediaScratchFileProvider.java

public static boolean isMediaScratchSpaceUri(final Uri uri) {
    if (uri == null) {
        return false;
    }//w  w  w .  j  av  a 2s . c  om

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

From source file:Main.java

/**
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.<br>
 * <br>//  w ww  .j  a v a 2  s. c  o  m
 * Callers should check whether the path is local before assuming it
 * represents a local file.
 *
 * @param context The context.
 * @param uri     The Uri to query.
 * @author paulburke
 * @see #isLocal(String)
 * @see #getFile(Context, Uri)
 */
@SuppressLint("NewApi")
public static String getPath(final Context context, final Uri uri) {

    if (DEBUG)
        Log.d(TAG + " File -",
                "Authority: " + uri.getAuthority() + ", Fragment: " + uri.getFragment() + ", Port: "
                        + uri.getPort() + ", Query: " + uri.getQuery() + ", Scheme: " + uri.getScheme()
                        + ", Host: " + uri.getHost() + ", Segments: " + uri.getPathSegments().toString());

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        if (isExternalStorageDocument(uri)) {
            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];
            }

            // TODO handle non-primary volumes
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            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);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            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);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

        // Return the remote address
        if (isGooglePhotosUri(uri))
            return uri.getLastPathSegment();

        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
public static String getFilePath(final Context context, final Uri uri) {
    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if ("com.android.externalStorage.documents".equalsIgnoreCase(uri.getAuthority())) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];
            if ("primary".equalsIgnoreCase(type) || "content".equalsIgnoreCase(uri.getScheme())) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }//from w w w  .java2 s  . c  o m
        }
        // DownloadsProvider
        else if ("com.android.providers.downloads.documents".equalsIgnoreCase(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);
        }
        // MediaProvider
        else if ("com.android.providers.media.documents".equalsIgnoreCase(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);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {
        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return "";
}

From source file:com.activiti.android.platform.provider.transfer.ContentTransferManager.java

private static boolean isMediaDocumentProvider(final Uri uri) {
    return "com.android.providers.media.documents".equals(uri.getAuthority());
}

From source file:org.coocood.vcontentprovider.VContentProvider.java

/**
 * If the JSONObject has any sub JSONObject, create a LinkedHashMap and
 * put the key to the sub JSONObject and the corresponding table name as value in it.
 * first in, first out(get updated)./*  w w w  .  jav a  2s  .  c o m*/
 */
public static ContentProviderResult[] updateWithJSONObject(Context context, Uri uri, JSONObject json,
        LinkedHashMap<String, String> subJSONObjectMap)
        throws JSONException, RemoteException, OperationApplicationException {
    Uri baseUri = new Uri.Builder().scheme(uri.getScheme()).authority(uri.getAuthority()).build();
    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
    addOperations(operations, uri, baseUri, json, subJSONObjectMap);
    return context.getContentResolver().applyBatch(uri.getAuthority(), operations);
}

From source file:org.coocood.vcontentprovider.VContentProvider.java

/**
 * see also {@link #updateWithJSONObject}
 *///from w ww.j a v  a 2  s .c o  m
public static ContentProviderResult[] updateWithJSONArray(Context context, Uri uri, JSONArray array,
        LinkedHashMap<String, String> subJSONObjectMap)
        throws RemoteException, OperationApplicationException, JSONException {
    Uri baseUri = new Uri.Builder().scheme(uri.getScheme()).authority(uri.getAuthority()).build();
    ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();
    for (int i = 0; i < array.length(); i++) {
        JSONObject json = array.getJSONObject(i);
        addOperations(operations, uri, baseUri, json, subJSONObjectMap);
    }
    return context.getContentResolver().applyBatch(uri.getAuthority(), operations);
}

From source file:com.pavlospt.rxfile.RxFile.java

private static boolean isMediaUri(Uri uri) {
    if (uri.getAuthority().equals(Constants.MEDIA_DOCUMENTS_AUTHORITY)) {
        return uri.getLastPathSegment().contains(Constants.IMAGE)
                || uri.getLastPathSegment().contains(Constants.VIDEO);
    }/*from   ww w.j  ava 2  s.  c  om*/
    return Constants.MEDIA_AUTHORITY.equals(uri.getAuthority());
}

From source file:com.pavlospt.rxfile.RxFile.java

private static boolean isMediaDocument(Uri uri) {
    return Constants.MEDIA_DOCUMENTS_AUTHORITY.equals(uri.getAuthority());
}

From source file:com.pavlospt.rxfile.RxFile.java

private static boolean isExternalStorageDocument(Uri uri) {
    return Constants.EXTERNAL_STORAGE_AUTHORITY.equals(uri.getAuthority());
}

From source file:com.pavlospt.rxfile.RxFile.java

private static boolean isDownloadsDocument(Uri uri) {
    return Constants.DOWNLOADS_DIRECTORY_AUTHORITY.equals(uri.getAuthority());
}