我正在使用此处指定的新 Kitkat 存储访问框架 (SAF): 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);
这与示例代码相同,但图像过滤器不起作用。 S5 或 Note3 上没有任何显示。视频 (video/*) 也是如此。我也尝试了不同的模式,例如 / 但没有用。
这看起来像是三星的问题,应该由他们解决,我只是想知道是否有人知道解决方法。
最佳答案
我在 samsung galaxy s4 上遇到了同样的问题。在我的研究过程中,我发现 galaxy s4 不支持媒体文档提供程序。通过查询媒体提供者接口(interface)解决了它。这就是我所做的:
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());
}
关于android - KitKat ACTION_OPEN_DOCUMENT 不显示三星设备上的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24616788/