F
F
falstaf2011-04-25 11:36:01
Java
falstaf, 2011-04-25 11:36:01

Java. Android. Writing content provider for WebView?

To load images in a WebView , a custom content provider was written that, by overriding the openFile method , must return a byte stream of binary image content.
However, there was the next snag. openFile returns a ParcelFileDescriptor , which can be obtained by calling

ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);

Where file is nothing but an instance of the File class .
I have an array of bytes ( byte[] ) - the binary content of the images. According to the terms of the TOR, the use of temporary files is not allowed. Thus, it is necessary to either create an in-memory File , without saving it to the SD card, or get the ParcelFileDescriptor in some other way.
A Google search and developer.android.com came up with the following code:
byte[] imageData = ...;
Parcel parcel = Parcel.obtain();
parcel.writeByteArray(imageData, 0, imageData.length);
return parcel.getFileDescriptor();

The method works successfully, no exceptions are thrown. But parcel.getFileDescriptor() returns null .
What could be the ways to solve this problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question