public static class PackageInstaller.Session
extends Object implements Closeable
| java.lang.Object | |
| android.content.pm.PackageInstaller.Session | |
正在积极安装的安装。 要使安装成功,所有现有的和新的软件包必须具有相同的软件包名称,版本代码和签名证书。
会话可能包含任意数量的拆分包。 如果应用程序尚不存在,则此会话必须包含基本包。
如果此会话中包含的APK已由现有安装定义(例如,相同的拆分名称),则此会话中的APK将替换现有的APK。
公共方法(Public methods) |
|
|---|---|
void |
abandon() 完全放弃这个会话,销毁所有分阶段的数据并使其无效。 |
void |
close() 发布此会话对象。 |
void |
commit(IntentSender statusReceiver) 尝试执行本次会议中的所有内容。 |
void |
fsync(OutputStream out) 确保给定流的任何未完成数据已提交给磁盘。 |
String[] |
getNames() 返回此会话中包含的所有APK名称。 |
InputStream |
openRead(String name) 打开流以从会话中读取APK文件。 |
OutputStream |
openWrite(String name, long offsetBytes, long lengthBytes) 打开一个流,将APK文件写入会话。 |
void |
removeSplit(String splitName) 删除分割。 |
void |
setStagingProgress(float progress) 设置暂存此会话的当前进度。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
void abandon ()
完全放弃这个会话,销毁所有分阶段的数据并使其无效。 被遗弃的会话将作为失败报告给PackageInstaller.SessionCallback听众。 这相当于打开会话并呼叫abandon() 。
void commit (IntentSender statusReceiver)
尝试执行本次会议中的所有内容。 这可能需要用户干预,因此可能不会立即发生。 提交的最终结果将通过给定的回调进行报告。
一旦调用此方法,就不会在会话中执行其他突变。 如果设备在会话完成之前重新启动,则可以再次提交会话。
| 参数(Parameters) | |
|---|---|
statusReceiver |
IntentSender
|
| 抛出异常(Throws) | |
|---|---|
SecurityException |
if streams opened through openWrite(String, long, long) are still open. |
void fsync (OutputStream out)
确保给定流的任何未完成数据已提交给磁盘。 这仅适用于从openWrite(String, long, long)返回的流。
| 参数(Parameters) | |
|---|---|
out |
OutputStream
|
| 抛出异常(Throws) | |
|---|---|
IOException |
|
String[] getNames ()
返回此会话中包含的所有APK名称。
这将返回以前通过 openWrite(String, long, long)写入的所有名称作为此会话的一部分。
| 返回(Returns) | |
|---|---|
String[] |
|
| 抛出异常(Throws) | |
|---|---|
SecurityException |
if called after the session has been committed or abandoned. |
IOException |
|
InputStream openRead (String name)
打开流以从会话中读取APK文件。
这仅适用于以前通过openWrite(String, long, long)作为本次会议的一部分编写的名称。 例如,此流可用于在提交之前计算书写APK的MessageDigest 。
| 参数(Parameters) | |
|---|---|
name |
String
|
| 返回(Returns) | |
|---|---|
InputStream |
|
| 抛出异常(Throws) | |
|---|---|
SecurityException |
if called after the session has been committed or abandoned. |
IOException |
|
OutputStream openWrite (String name, long offsetBytes, long lengthBytes)
打开一个流,将APK文件写入会话。
返回的流将开始在基础文件中请求的偏移量处写入数据,该数据可用于恢复部分写入的文件。 如果指定了有效的文件长度,系统将预分配底层磁盘空间以优化磁盘上的放置。 强烈建议在知道时提供有效的文件长度。
您可以将数据写入返回的流中,根据需要可选择调用fsync(OutputStream) ,以确保字节已保存到磁盘,然后在完成时关闭。 在致电commit(IntentSender)之前,所有流必须关闭。
| 参数(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 |
long: offset into the file to begin writing at, or 0 to start at the beginning of the file. |
lengthBytes |
long: 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) | |
|---|---|
OutputStream |
|
| 抛出异常(Throws) | |
|---|---|
IOException |
if trouble opening the file for writing, such as lack of disk space or unavailable media. |
SecurityException |
if called after the session has been committed or abandoned. |
void removeSplit (String splitName)
删除分割。
拆分删除发生在添加新APK之前。 如果升级功能拆分,则在升级之前删除拆分并不是期望也不可取的。
当拆分拆分与新APK捆绑在一起时,packageName必须相同。
| 参数(Parameters) | |
|---|---|
splitName |
String
|
| 抛出异常(Throws) | |
|---|---|
IOException |
|
void setStagingProgress (float progress)
设置暂存此会话的当前进度。 有效值是0到1之间的任何值。
请注意,此进度可能并不直接与 onProgressChanged(int, float)报告的值相对应,因为系统可能会划出整体进度的一部分来表示其内部安装工作。
| 参数(Parameters) | |
|---|---|
progress |
float
|