Udostępnij za pośrednictwem


ContentResolver.OpenFileDescriptor Method

Definition

Overloads

OpenFileDescriptor(Uri, String)

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

OpenFileDescriptor(Uri, String, CancellationSignal)

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

OpenFileDescriptor(Uri, String)

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

[Android.Runtime.Register("openFileDescriptor", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;", "")]
public Android.OS.ParcelFileDescriptor? OpenFileDescriptor (Android.Net.Uri uri, string mode);
[<Android.Runtime.Register("openFileDescriptor", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;", "")>]
member this.OpenFileDescriptor : Android.Net.Uri * string -> Android.OS.ParcelFileDescriptor

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 if no file exists under the URI or the mode is invalid.

Remarks

Open a raw file descriptor to access data under a URI. This is like #openAssetFileDescriptor(Uri, String), but uses the underlying ContentProvider#openFile ContentProvider.openFile()} method, so will <em>not</em> work with providers that return sub-sections of files. If at all possible, you should use #openAssetFileDescriptor(Uri, String). You will receive a FileNotFoundException exception if the provider returns a sub-section of a file.

<h5>Accepts the following URI schemes:</h5> <ul> <li>content (#SCHEME_CONTENT)</li> <li>file (#SCHEME_FILE)</li> </ul>

See #openAssetFileDescriptor(Uri, String) for more information on these schemes.

If opening with the exclusive "r" or "w" modes, the returned ParcelFileDescriptor could be a pipe or socket pair to enable streaming of data. Opening with the "rw" mode implies a file on disk that supports seeking. If possible, always use an exclusive mode to give the underlying ContentProvider the most flexibility.

If you are writing a file, and need to communicate an error to the provider, use ParcelFileDescriptor#closeWithError(String).

Java documentation for android.content.ContentResolver.openFileDescriptor(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.ContentResolver.OpenAssetFileDescriptor(Android.Net.Uri%2c+System.String)>

Applies to

OpenFileDescriptor(Uri, String, CancellationSignal)

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

[Android.Runtime.Register("openFileDescriptor", "(Landroid/net/Uri;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/os/ParcelFileDescriptor;", "")]
public Android.OS.ParcelFileDescriptor? OpenFileDescriptor (Android.Net.Uri uri, string mode, Android.OS.CancellationSignal? cancellationSignal);
[<Android.Runtime.Register("openFileDescriptor", "(Landroid/net/Uri;Ljava/lang/String;Landroid/os/CancellationSignal;)Landroid/os/ParcelFileDescriptor;", "")>]
member this.OpenFileDescriptor : Android.Net.Uri * string * Android.OS.CancellationSignal -> Android.OS.ParcelFileDescriptor

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.

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 if no file exists under the URI or the mode is invalid.

Remarks

Open a raw file descriptor to access data under a URI. This is like #openAssetFileDescriptor(Uri, String), but uses the underlying ContentProvider#openFile ContentProvider.openFile()} method, so will <em>not</em> work with providers that return sub-sections of files. If at all possible, you should use #openAssetFileDescriptor(Uri, String). You will receive a FileNotFoundException exception if the provider returns a sub-section of a file.

<h5>Accepts the following URI schemes:</h5> <ul> <li>content (#SCHEME_CONTENT)</li> <li>file (#SCHEME_FILE)</li> </ul>

See #openAssetFileDescriptor(Uri, String) for more information on these schemes.

If opening with the exclusive "r" or "w" modes, the returned ParcelFileDescriptor could be a pipe or socket pair to enable streaming of data. Opening with the "rw" mode implies a file on disk that supports seeking. If possible, always use an exclusive mode to give the underlying ContentProvider the most flexibility.

If you are writing a file, and need to communicate an error to the provider, use ParcelFileDescriptor#closeWithError(String).

Java documentation for android.content.ContentResolver.openFileDescriptor(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.ContentResolver.OpenAssetFileDescriptor(Android.Net.Uri%2c+System.String)>

Applies to