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();
}