我有一种方法可以从我的应用程序中打开文件,这种方法在内部存储的每个操作系统上运行良好,但是当 OS 6 和更高版本的 sdcard 想要打开文件时,我发现了一个错误:
Failed to find the configured root that contains /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();
}
最佳答案
试着把它放在你的 android list 上。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
关于android - Sdcard 文件无法在 OS 6 及更高版本中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53863913/