简体   繁体   English

Android-找不到内容提供者文件异常

[英]Android - content provider file not found exception

I've a little content provider to open a simple pdf in my app package with an external application, but whe the open() run the parcelfiledescription return me a FileNotFoundException . 我有一个小的内容提供商,可以使用外部应用程序在我的应用程序包中打开一个简单的pdf,但是运行open()的parcelfiledescription返回一个FileNotFoundException

I don't understand what is the right sintax to give the correct file path to the parcel descriptor... 我不明白什么是正确的sintax来为包裹描述符提供正确的文件路径...

    public ParcelFileDescriptor openFile(Uri uri, String mode) {
            Log.i("info","eseguo providing");
            URI uri1 = URI.create("file:///data/data/package.name/assets/prova.pdf");
            File file = new File(uri1);
            ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_WRITE);        
            return parcel;
}

Thanks for any help! 谢谢你的帮助!


i've tried this simple code: 我试过这个简单的代码:

URI uri1 = URI.create("file:///android_asset/prova.pdf");
File file = new File(uri1);
Log.i("info","file exist: " + file.exists());

but it return ever false! 但它返回永远是假的!

From [ParcelFileDescriptor.open method][1] (bold emphasis mine) 来自[ParcelFileDescriptor.open方法] [1](加粗强调)

FileNotFoundException Throws FileNotFoundException if the given file does not exist or can not be opened with the requested mode . FileNotFoundException如果给定文件不存在或无法以请求的模式打开,则抛出FileNotFoundException。

Have you tried changing the MODE to MODE_READ_ONLY and see if that works? 您是否尝试过将MODE更改为MODE_READ_ONLY ,看看是否MODE_READ_ONLY

[1]: http://developer.android.com/reference/android/os/ParcelFileDescriptor.html#open(java.io.File , int) [1]: http : //developer.android.com/reference/android/os/ParcelFileDescriptor.html#open(java.io.File ,int)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM