Udostępnij za pośrednictwem


ContentResolver.OpenAssetFileDescriptor Method

Definition

Overloads

OpenAssetFileDescriptor(Uri, String)

Open a raw file descriptor to access data under a URI.

OpenAssetFileDescriptor(Uri, String, CancellationSignal)

Open a raw file descriptor to access data under a URI.

OpenAssetFileDescriptor(Uri, String)

Open a raw file descriptor to access data under a URI.

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

Parameters

uri
Uri

The desired URI to open.

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 ParcelFileDescriptor pointing to the file or null if the provider recently crashed. You own this descriptor and are responsible for closing it when done.

Attributes

Exceptions

Throws FileNotFoundException of no file exists under the URI or the mode is invalid.

Remarks

Open a raw file descriptor to access data under a URI. This interacts with the underlying ContentProvider#openAssetFile method of the provider associated with the given URI, to retrieve any file stored there.

<h5>Accepts the following URI schemes:</h5> <ul> <li>content (#SCHEME_CONTENT)</li> <li>android.resource (#SCHEME_ANDROID_RESOURCE)</li> <li>file (#SCHEME_FILE)</li> </ul> <h5>The android.resource (#SCHEME_ANDROID_RESOURCE) Scheme</h5>

A Uri object can be used to reference a resource in an APK file. The Uri should be one of the following formats: <ul> <li>android.resource://package_name/id_number<br/> package_name is your package name as listed in your AndroidManifest.xml. For example com.example.myapp<br/> id_number is the int form of the ID.<br/> The easiest way to construct this form is

Uri uri = Uri.parse("android.resource://com.example.myapp/" + R.raw.my_resource");

</li> <li>android.resource://package_name/type/name<br/> package_name is your package name as listed in your AndroidManifest.xml. For example com.example.myapp<br/> type is the string form of the resource type. For example, raw or drawable. name is the string form of the resource name. That is, whatever the file name was in your res directory, without the type extension. The easiest way to construct this form is

Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");

</li> </ul>

Note that if this function is called for read-only input (mode is "r") on a content: URI, it will instead call #openTypedAssetFileDescriptor for you with a MIME type of "*&#47;*". This allows such callers to benefit from any built-in data conversion that a provider implements.

Java documentation for android.content.ContentResolver.openAssetFileDescriptor(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.

Applies to

OpenAssetFileDescriptor(Uri, String, CancellationSignal)

Open a raw file descriptor to access data under a URI.

[Android.Runtime.Register("openAssetFileDescriptor", "(Landroid/net/Uri;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/content/res/AssetFileDescriptor;", "")]
public Android.Content.Res.AssetFileDescriptor? OpenAssetFileDescriptor (Android.Net.Uri uri, string mode, Android.OS.CancellationSignal? cancellationSignal);
[<Android.Runtime.Register("openAssetFileDescriptor", "(Landroid/net/Uri;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/content/res/AssetFileDescriptor;", "")>]
member this.OpenAssetFileDescriptor : Android.Net.Uri * string * Android.OS.CancellationSignal -> Android.Content.Res.AssetFileDescriptor

Parameters

uri
Uri

The desired URI to open.

mode
String

The string representation of the file mode. Can be "r", "w", "wt", "wa", "rw" or "rwt". Please note "w" is write only and "wt" is write and truncate. SeeParcelFileDescriptor#parseMode for more details.

cancellationSignal
CancellationSignal

A signal to cancel the operation in progress, or null if none. If the operation is canceled, then OperationCanceledException will be thrown.

Returns

Returns a new ParcelFileDescriptor pointing to the file or null if the provider recently crashed. You own this descriptor and are responsible for closing it when done.

Attributes

Exceptions

Throws FileNotFoundException of no file exists under the URI or the mode is invalid.

Remarks

Open a raw file descriptor to access data under a URI. This interacts with the underlying ContentProvider#openAssetFile method of the provider associated with the given URI, to retrieve any file stored there.

<h5>Accepts the following URI schemes:</h5> <ul> <li>content (#SCHEME_CONTENT)</li> <li>android.resource (#SCHEME_ANDROID_RESOURCE)</li> <li>file (#SCHEME_FILE)</li> </ul> <h5>The android.resource (#SCHEME_ANDROID_RESOURCE) Scheme</h5>

A Uri object can be used to reference a resource in an APK file. The Uri should be one of the following formats: <ul> <li>android.resource://package_name/id_number<br/> package_name is your package name as listed in your AndroidManifest.xml. For example com.example.myapp<br/> id_number is the int form of the ID.<br/> The easiest way to construct this form is

Uri uri = Uri.parse("android.resource://com.example.myapp/" + R.raw.my_resource");

</li> <li>android.resource://package_name/type/name<br/> package_name is your package name as listed in your AndroidManifest.xml. For example com.example.myapp<br/> type is the string form of the resource type. For example, raw or drawable. name is the string form of the resource name. That is, whatever the file name was in your res directory, without the type extension. The easiest way to construct this form is

Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");

</li> </ul>

Note that if this function is called for read-only input (mode is "r") on a content: URI, it will instead call #openTypedAssetFileDescriptor for you with a MIME type of "*&#47;*". This allows such callers to benefit from any built-in data conversion that a provider implements.

Java documentation for android.content.ContentResolver.openAssetFileDescriptor(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.

Applies to