我在三星galaxy s4上遇到了同样的问题。在我的研究中,我发现 Galaxy s4 不支持媒体文档提供程序。通过查询媒体提供者接口解决了它。这就是我所做的:
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());
}