Sdcard File not open in OS 6 and later

社会主义新天地 提交于 2019-12-24 01:58:16

问题


I have one method which open files from my app and this method running well on every OS for Internal Storage but when sdcard from OS 6 and upper want to open the file then I found an error :

Failed to find the configured root that contains /storage/BE02-07BA/WhatsApp/Media/WallPaper/download (1).jpg

My code is below :

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:


Try to put this on your android manifest.

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



来源:https://stackoverflow.com/questions/53863913/sdcard-file-not-open-in-os-6-and-later

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!