Android.Content.ContentProvider.OpenAssetFile Method
This is like ContentProvider.OpenFile(Android.Net.Uri, System.String), but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .apk.

Syntax

[Android.Runtime.Register("openAssetFile", "(Landroid/net/Uri;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/content/res/AssetFileDescriptor;", "GetOpenAssetFile_Landroid_net_Uri_Ljava_lang_String_Landroid_os_CancellationSignal_Handler")]
public virtual Android.Content.Res.AssetFileDescriptor OpenAssetFile (Android.Net.Uri uri, string mode, Android.OS.CancellationSignal signal)

See Also

ContentProvider.OpenFile(Android.Net.Uri, System.String)
ContentProvider.OpenFileHelper(Android.Net.Uri, System.String)
ContentProvider.GetType(Android.Net.Uri)

Parameters

uri
The URI whose file is to be opened.
mode
Access mode for the file. May be "r" for read-only access, "w" for write-only access (erasing whatever data is currently in the file), "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data, and "rwt" for read and write access that truncates any existing file.
signal
A signal to cancel the operation in progress, or null if none. For example, if you are downloading a file from the network to service a "rw" mode request, you should periodically call Android.OS.CancellationSignal.ThrowIfCanceled to check whether the client has canceled the request and abort the download.

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

This is like ContentProvider.OpenFile(Android.Net.Uri, System.String), but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .apk. This method can be called from multiple threads, as described in Processes and Threads.

If you implement this, your clients must be able to deal with such file slices, either directly with ContentResolver.OpenAssetFileDescriptor(Android.Net.Uri, System.String), or by using the higher-level ContentResolver.OpenInputStream(Android.Net.Uri) or ContentResolver.OpenOutputStream(Android.Net.Uri) methods.

The returned AssetFileDescriptor can be a pipe or socket pair to enable streaming of data.

If you are implementing this to return a full file, you should create the AssetFileDescriptor with Android.Content.Res.AssetFileDescriptor.UnknownLength to be compatible with applications that cannot handle sub-sections of files.

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.

[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