2015-07-10 19 views
32

我試圖用FileProvider從私人path.Facing播放視頻安卓:FileProvider拋出:IllegalArgumentException無法找到配置的根包含/data/data/**/files/Videos/final.mp4

java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/XXXXX(Package)/files/Videos/final.mp4 

代碼:

<paths> 
    <files-path path="my_docs" name="Videos/" /> 
</paths> 

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

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

對此有何線索?

感謝 尼茨

+0

我得到的「屬性丟失了Android命名空間前綴」在@ XML/file_paths同時實施Fileprovider..later不知何故,我結束了亂放的名稱和路徑,並結束了與此問題.. – NitZRobotKoder

回答

47

你有你的name和你path翻轉。 nameUripath是文件系統根目錄中的相對位置。

轉到搭配:

<paths> 
    <files-path name="my_docs" path="Videos/" /> 
</paths> 
+0

天哪!不知道我是如何放錯它的。您保存了我的一天,謝謝.. :-) – NitZRobotKoder

+0

卡住了「java.lang.SecurityException:權限拒絕:從ProcessRecord打開提供程序android.support.v4.content.FileProvider {44c35948 3239:com.mxtech.videoplayer.ad/u0a307} (pid = 3239,uid = 10307)不會從uid 10221導出「試圖通過意圖傳遞給視頻播放器。 – NitZRobotKoder

+2

@NitZRobotKoder:如果通過「視頻播放器」,你的意思是一個單獨的應用程序,然後將'FLAG_GRANT_READ_URI_PERMISSION'添加到你用'startActivity()'用的'Intent'來啓動播放器。如果「視頻播放器」的意思是「MediaPlayer」,那麼我將使用「FileDescriptor」路線而不是「ContentProvider」。如果通過「視頻播放器」,你的意思是'VideoView',我沒有任何建議。 – CommonsWare

相關問題