Freigeben über


ContentProvider.OpenAssetFile Method

Definition

Overloads

OpenAssetFile(Uri, String)

This is like #openFile, but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .

OpenAssetFile(Uri, String, CancellationSignal)

This is like #openFile, but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .

OpenAssetFile(Uri, String)

This is like #openFile, but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .

[Android.Runtime.Register("openAssetFile", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;", "GetOpenAssetFile_Landroid_net_Uri_Ljava_lang_String_Handler")]
public virtual Android.Content.Res.AssetFileDescriptor? OpenAssetFile (Android.Net.Uri uri, string mode);
[<Android.Runtime.Register("openAssetFile", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/content/res/AssetFileDescriptor;", "GetOpenAssetFile_Landroid_net_Uri_Ljava_lang_String_Handler")>]
abstract member OpenAssetFile : Android.Net.Uri * string -> Android.Content.Res.AssetFileDescriptor
override this.OpenAssetFile : Android.Net.Uri * string -> Android.Content.Res.AssetFileDescriptor

Parameters

uri
Uri

The URI whose file is to be opened.

mode
String

The string representation of the file mode. Can be "r", "w", "wt", "wa", "rw" or "rwt". Please note the exact implementation of these may differ for each Provider implementation - for example, "w" may or may not truncate.

Returns

Returns a new AssetFileDescriptor which you can use to access the file.

Attributes

Exceptions

Throws FileNotFoundException if there is no file associated with the given URI or the mode is invalid.

Throws SecurityException if the caller does not have permission to access the file.

Remarks

This is like #openFile, 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, or by using the higher-level ContentResolver#openInputStream ContentResolver.openInputStream or ContentResolver#openOutputStream ContentResolver.openOutputStream methods.

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

<p class="note">If you are implementing this to return a full file, you should create the AssetFileDescriptor with AssetFileDescriptor#UNKNOWN_LENGTH to be compatible with applications that cannot handle sub-sections of files.

<p class="note">For use in Intents, you will want to implement #getType 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.</p>

<p class="note">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.</p>

Java documentation for android.content.ContentProvider.openAssetFile(android.net.Uri, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

  • <xref:Android.Content.ContentProvider.OpenFile(Android.Net.Uri%2c+System.String)>
  • <xref:Android.Content.ContentProvider.OpenFileHelper(Android.Net.Uri%2c+System.String)>
  • GetType(Uri)

Applies to

OpenAssetFile(Uri, String, CancellationSignal)

This is like #openFile, but can be implemented by providers that need to be able to return sub-sections of files, often assets inside of their .

[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);
[<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")>]
abstract member OpenAssetFile : Android.Net.Uri * string * Android.OS.CancellationSignal -> Android.Content.Res.AssetFileDescriptor
override this.OpenAssetFile : Android.Net.Uri * string * Android.OS.CancellationSignal -> Android.Content.Res.AssetFileDescriptor

Parameters

uri
Uri

The URI whose file is to be opened.

mode
String

The string representation of the file mode. Can be "r", "w", "wt", "wa", "rw" or "rwt". Please note the exact implementation of these may differ for each Provider implementation - for example, "w" may or may not truncate.

signal
CancellationSignal

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 CancellationSignal#throwIfCanceled() to check whether the client has canceled the request and abort the download.

Returns

Returns a new AssetFileDescriptor which you can use to access the file.

Attributes

Exceptions

Throws FileNotFoundException if there is no file associated with the given URI or the mode is invalid.

Throws SecurityException if the caller does not have permission to access the file.

Remarks

This is like #openFile, 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, or by using the higher-level ContentResolver#openInputStream ContentResolver.openInputStream or ContentResolver#openOutputStream ContentResolver.openOutputStream methods.

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

<p class="note">If you are implementing this to return a full file, you should create the AssetFileDescriptor with AssetFileDescriptor#UNKNOWN_LENGTH to be compatible with applications that cannot handle sub-sections of files.

<p class="note">For use in Intents, you will want to implement #getType 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.</p>

<p class="note">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.</p>

Java documentation for android.content.ContentProvider.openAssetFile(android.net.Uri, java.lang.String, android.os.CancellationSignal).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

See also

  • <xref:Android.Content.ContentProvider.OpenFile(Android.Net.Uri%2c+System.String)>
  • <xref:Android.Content.ContentProvider.OpenFileHelper(Android.Net.Uri%2c+System.String)>
  • GetType(Uri)

Applies to