无法在OS 6和更高版本中打开Sdcard文件

时间:2018-12-20 07:07:33

标签: android android-external-storage fileprovider

我有一种方法可以从我的应用程序中打开文件,并且该方法在每个用于内部存储的操作系统上都能很好地运行,但是当OS 6和更高版本中的sdcard要打开文件时,我发现了一个错误:

  

无法找到包含以下内容的已配置根目录   / storage / BE02-07BA / WhatsApp / Media / WallPaper / download(1).jpg

我的代码在下面:

try {
                    File f = new File(feedItem.getFilePath());
                    MimeTypeMap map = MimeTypeMap.getSingleton();
                    String url = f.getName();
                    url = URLEncoder.encode(url, "UTF-16").replace("+", "%20");
                    String ext = MimeTypeMap.getFileExtensionFromUrl(url);
                    String type = map.getMimeTypeFromExtension(ext.toLowerCase());
                    if (type == null)
                        type = "*/*";
                    Uri uri = Uri.parse("www.google.com");
                    Intent type_intent = new Intent(Intent.ACTION_VIEW, uri);
                    Uri data = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".provider",f);
                    type_intent.setDataAndType(data, type);
                    type_intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

                    mContext.startActivity(type_intent);
                } catch (Exception e) {
                    // Auto-generated catch block
                    e.printStackTrace();
                }

1 个答案:

答案 0 :(得分:0)

尝试将其放在您的android清单中。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

相关问题