Josu Goñi
Josu Goñi

Reputation: 1274

Where do I find the standard uri authorities in Android and how they work?

I have found this snippet of code:

    @TargetApi(Build.VERSION_CODES.KITKAT)
    public static String getPath(final Context context, final Uri uri) {

        final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
        if (isKitKat) {
            // ExternalStorageProvider
            if (isExternalStorageDocument(uri)) {
                final String docId = uri.getPath();
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("/tree/primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }                
            }           
        }
        return null;
    }

    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is ExternalStorageProvider.
     */
    public static boolean isExternalStorageDocument(Uri uri) {
        return "com.android.externalstorage.documents".equals(uri.getAuthority());
    }

I want to use it to translate uris to full paths, and I want more information about what I can get as "authority", but in the official documentation I only find how to create an authority, not information about what can I expect to find on a normal device.

There is even more complex code like this one from this question but I would like to find official documentation behind this kind of logic. A good explanation of how this works is also welcomed.

Upvotes: 0

Views: 316

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006924

I want to use it to translate uris to full paths

That will not be reliable. A Uri is an opaque identifier, nothing more.

I want more information about what I can get as "authority", but in the official documentation I only find how to create an authority, not information about what can I expect to find on a normal device

That is because this information varies by individual device:

  • OS version
  • Device manufacturer
  • User-installed apps
  • App versions

None of it is documented, because it is all internal implementation of apps (from the core OS, devices, and user-installed apps).

I would like to find official documentation behind this kind of logic

There is none.

Upvotes: 2

Related Questions