Android.Content.ContentProvider.OpenFile Method
Override this to handle requests to open a file blob.

Syntax

[Android.Runtime.Register("openFile", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;", "GetOpenFile_Landroid_net_Uri_Ljava_lang_String_Handler")]
public virtual Android.OS.ParcelFileDescriptor OpenFile (Android.Net.Uri uri, string mode)

See Also

ContentProvider.OpenAssetFile(Android.Net.Uri, System.String)
ContentProvider.OpenFileHelper(Android.Net.Uri, System.String)
ContentProvider.GetType(Android.Net.Uri)
Android.OS.ParcelFileDescriptor.ParseMode(string)

Parameters

uri
The URI whose file is to be opened.
mode
Access mode for the file. May be "r" for read-only access, "rw" for read and write access, or "rwt" for read and write access that truncates any existing file.

Returns

Documentation for this section has not yet been entered.

Exceptions

TypeReason
Java.IO.FileNotFoundExceptionThrows FileNotFoundException if there is no file associated with the given URI or the mode is invalid.
Java.Lang.SecurityExceptionThrows SecurityException if the caller does not have permission to access the file.

Remarks

Override this to handle requests to open a file blob. The default implementation always throws Java.IO.FileNotFoundException. This method can be called from multiple threads, as described in Processes and Threads.

This method returns a ParcelFileDescriptor, which is returned directly to the caller. This way large data (such as images and documents) can be returned without copying the content.

The returned ParcelFileDescriptor is owned by the caller, so it is their responsibility to close it when done. That is, the implementation of this method should create a new ParcelFileDescriptor for each call.

If opened with the exclusive "r" or "w" modes, the returned ParcelFileDescriptor can be a pipe or socket pair to enable streaming of data. Opening with the "rw" or "rwt" modes implies a file on disk that supports seeking.

If you need to detect when the returned ParcelFileDescriptor has been closed, or if the remote process has crashed or encountered some other error, you can use Android.OS.ParcelFileDescriptor.Open(Java.IO.File, Android.OS.ParcelFileMode, Android.OS.ParcelFileMode, Android.OS.ParcelFileMode), Android.OS.ParcelFileDescriptor.CreateReliablePipe, or Android.OS.ParcelFileDescriptor.CreateReliableSocketPair.

For use in Intents, you will want to implement ContentProvider.GetType(Android.Net.Uri) to return the appropriate MIME type for the data returned here with the same URI. This will allow intent resolution to automatically determine the data MIME type and select the appropriate matching targets as part of its operation.

For better interoperability with other applications, it is recommended that for any URIs that can be opened, you also support queries on them containing at least the columns specified by Android.Provider.OpenableColumns. You may also want to support other common columns if you have additional meta-data to supply, such as NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html#DATE_ADDED in NoType:android/provider/MediaStore$MediaColumns;Href=../../../reference/android/provider/MediaStore.MediaColumns.html.

[Android Documentation]

Requirements

Namespace: Android.Content
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1