frapim
frapim

Reputation: 63

KitKat ACTION_OPEN_DOCUMENT does not show documents on Samsung devices

I'm using the new Kitkat Storage Access Framework (SAF) as specified here: https://developer.android.com/guide/topics/providers/document-provider.html

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, 0);

This is the same as the example code but the images filter is not working. Nothing shows up on the S5 or the Note3. The same happens for video (video/*). I also tried different patterns like / to not avail.

This looks like a Samsung issue that should be addressed by them, I'm just wondering if anyone knows a workaround.

Upvotes: 6

Views: 4188

Answers (2)

AjayV
AjayV

Reputation: 209

I was facing the same issue on samsung galaxy s4. During my research i figured out that the galaxy s4 was not supporting the Media document provider. Solved it by querying the media provider interface. This is what i did:

private void launchGallery()
{
    final Intent intent = new Intent();
    // Api 19 and above should access the Storage Access Framework
    if ( isMediaProviderPresent())
        intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
    else
        intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // Multi Picking is supported on api 18 and above.
    if (isApi18Above())
        intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

    startActivityForResult(Intent.createChooser(intent,"chooser"),
        RESULT_PHOTO_FROM_GALLERY);
}


private boolean isMediaProviderSupported()
{
    if(isApi19Above())
    {
        final PackageManager pm = getActivity().getPackageManager();
        // Pick up provider with action string
        final Intent i = new Intent(DocumentsContract.PROVIDER_INTERFACE);
        final List<ResolveInfo> providers = pm.queryIntentContentProviders(i, 0);
        for (ResolveInfo info : providers)
        {
            if(info != null && info.providerInfo != null)
            {
                final String authority = info.providerInfo.authority;
                if(isMediaDocumentProvider(Uri.parse("content://"+authority)))
                    return true;
            }
        }
    }
    return false;
}

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

Upvotes: 9

Ray B.
Ray B.

Reputation: 56

I had the same on my Galaxy S4, and the only workaround I found was to reuse the old way:

Intent photoPickerIntent = new Intent();    
photoPickerIntent.setAction(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 0);

But I suppose you first want to be sure to be on the specific device, since it works well with the Intent.ACTION_OPEN_DOCUMENT on other devices ... (I tried on Wiko Cink Slim and Nexus 5, with Android 4.4.2).

Hope it helps you

Upvotes: 3

Related Questions