I want to develop an App that uses the Storage Access Framework but processes the provided files with JNI native code.
Via the Storage Access Framework I get a Uri after a call to startActivityForResult() with a Intent.ACTION_OPEN_DOCUMENT intent. From this I can get an InputStream, ParcelFileDescriptor or similar.
Is there a way to get from this something (like for example a FILE) that I can pass on to my native code so that it can directly read from/write to the file provided by the content provider?
Background:
The C part of the JNI interface (which I didn't write but can modify/extend) can load two kinds of data
- files specified by a file name
const char *filenamethat can be opened withopen() - data in a buffer
jbyteArray arraycontaining the bytes that make up the "file"
and can write to
- a file path
const char *filenamethat can be opened withfopen()
Currently, when opening a file with Intent.ACTION_OPEN_DOCUMENT the Uri uri obtained in onActivityResult() is converted to an input stream with getContentResolver().openInputStream(uri) and then read into a byte[] buffer which is passed to the native code. Once the native code is done, it saves the result to a temporary file whose path is passed back to the Java side. The Java code then reads the temporary file and puts its content into a FileOutputStream obtained from the uri.
This is obviously horribly inefficient and ugly.