Sdcard File not open in OS 6 and later
Asked Answered
A

1

2

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();
}
Audie answered 20/12, 2018 at 7:7 Comment(6)
have you given run time permission for storageChapnick
yes internal storage is working fineAudie
i am asking about run time permissionChapnick
please share your full codeChapnick
@YogeshBorhade above is my full code to open file and in this line I am getting error Uri data = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".provider",f);Audie
Yes all run time permission is done from my side YogeshAudie
C
0

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" />

Crump answered 20/12, 2018 at 8:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.