Share via


PackageInstaller.Session.OpenWrite(String, Int64, Int64) Method

Definition

Open a stream to write an APK file into the session.

[Android.Runtime.Register("openWrite", "(Ljava/lang/String;JJ)Ljava/io/OutputStream;", "GetOpenWrite_Ljava_lang_String_JJHandler")]
public virtual System.IO.Stream OpenWrite (string name, long offsetBytes, long lengthBytes);
[<Android.Runtime.Register("openWrite", "(Ljava/lang/String;JJ)Ljava/io/OutputStream;", "GetOpenWrite_Ljava_lang_String_JJHandler")>]
abstract member OpenWrite : string * int64 * int64 -> System.IO.Stream
override this.OpenWrite : string * int64 * int64 -> System.IO.Stream

Parameters

name
String

arbitrary, unique name of your choosing to identify the APK being written. You can open a file again for additional writes (such as after a reboot) by using the same name. This name is only meaningful within the context of a single install session.

offsetBytes
Int64

offset into the file to begin writing at, or 0 to start at the beginning of the file.

lengthBytes
Int64

total size of the file being written, used to preallocate the underlying disk space, or -1 if unknown. The system may clear various caches as needed to allocate this space.

Returns

Attributes

Remarks

Open a stream to write an APK file into the session.

The returned stream will start writing data at the requested offset in the underlying file, which can be used to resume a partially written file. If a valid file length is specified, the system will preallocate the underlying disk space to optimize placement on disk. It's strongly recommended to provide a valid file length when known.

You can write data into the returned stream, optionally call #fsync(OutputStream) as needed to ensure bytes have been persisted to disk, and then close when finished. All streams must be closed before calling #commit(IntentSender).

Java documentation for android.content.pm.PackageInstaller.Session.openWrite(java.lang.String, long, long).

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