开发者

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.

I don't understand what is the right sintax to give the correct file path to the parcel descriptor...

    public ParcelFileDescriptor openFile(Uri uri, String mode) {
            Log.i("info","eseguo providing");
            URI uri1开发者_StackOverflow中文版 = 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)

FileNotFoundException Throws FileNotFoundException if the given file does not exist or can not be opened with the requested mode.

Have you tried changing the MODE to MODE_READ_ONLY and see if that works?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜