Nit*_*der 40 android android-fileprovider
我正试图用FileProvider
私人路径播放视频.面对
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/XXXXX(Package)/files/Videos/final.mp4
Run Code Online (Sandbox Code Playgroud)
码:
<paths>
<files-path path="my_docs" name="Videos/" />
</paths>
Run Code Online (Sandbox Code Playgroud)
Java代码:
File imagePath = new File(getFilesDir(), "Videos");
File newFile = new File(imagePath, "final.mp4");
Log.d(TAG, "-------------newFile:"+newFile.exists());//True here
//Exception in below line
Uri contentUri = FileProvider.getUriForFile(this,"com.wow.fileprovider", newFile);
Run Code Online (Sandbox Code Playgroud)
的Manifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.wow.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
Run Code Online (Sandbox Code Playgroud)
这有什么线索吗?
谢谢Nitz
Com*_*are 56
你有你name
和你的path
翻转.name
是什么Uri
,path
是文件系统根目录中的相对位置.
跟着:
<paths>
<files-path name="my_docs" path="Videos/" />
</paths>
Run Code Online (Sandbox Code Playgroud)
小智 11
将您的提供程序 XML 更改为此。
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external_files" path="." />
<root-path name="external_files" path="/storage/" />
</paths>
Run Code Online (Sandbox Code Playgroud)
我有非常相同的基本情况。我正确定义了所有内容(xml 中的文件路径),但还有一件事会导致相同的异常。我添加了另一个答案作为补充,并且评论不太容易阅读。
我创建/读取了存储文件的目录,例如:
context.getDir("Documents", Context.MODE_PRIVATE)
Run Code Online (Sandbox Code Playgroud)
这导致路径如下:
/data/user/0/ch.myapp/app_Documents/6c3c70d5-af66-48ef-8dfc-f4341de4e1bd.docx
然后我将创建目录更改为:
File directory = new File(context.getFilesDir(), "Documents");
if (!directory.exists()) {
directory.mkdir();
}
Run Code Online (Sandbox Code Playgroud)
这导致路径如下:
/data/user/0/ch.myapp/files/Documents/6c3c70d5-af66-48ef-8dfc-f4341de4e1bd.docx
根据文档Open a directory就我所知,这两种方法应该是等效的。但它创造了一条不同的道路......也许文档中的表述对我来说不清楚,但对我来说它写错了。
getDir(名称,模式)
在应用程序的唯一文件系统目录中创建一个新目录(或打开一个现有目录)。这个新目录出现在 getFilesDir() 提供的目录中。
归档时间: |
|
查看次数: |
39550 次 |
最近记录: |