getDiskInfo
API_LEVEL
2.0开始支持,API 兼容性请参考 API_LEVEL。
获取设备存储空间概况,包括总空间、可用空间以及小程序、表盘、音乐、系统的分类占用。不传参数时同步返回结果;从 API_LEVEL 3.0 开始支持传入回调异步查询,推荐使用异步方式。
类型
function getDiskInfo(): Result
function getDiskInfo(callback: Callback): void
参数
Result
| 属性 | 类型 | 说明 | API_LEVEL |
|---|---|---|---|
| total | number | 总空间(字节) | 2.0 |
| free | number | 可用空间(字节) | 2.0 |
| app | number | 小程序占用空间(字节) | 2.0 |
| watchface | number | 表盘占用空间(字节) | 2.0 |
| music | number | 音乐占用空间(字节) | 2.0 |
| system | number | 系统占用空间(字节) | 2.0 |
Callback
API_LEVEL
3.0开始支持,API 兼容性请参考 API_LEVEL。
| 类型 | 说明 |
|---|---|
(diskInfo: Result) => void | 查询完成时接收设备存储空间信息的回调,容量单位为字节 |
代码示例
import { getDiskInfo } from '@zos/device'
// Synchronous query
const diskInfo = getDiskInfo()
console.log(diskInfo.total, diskInfo.free)
// Asynchronous query (API_LEVEL 3.0+)
getDiskInfo((diskInfo) => {
console.log(diskInfo.total, diskInfo.free)
console.log(diskInfo.app, diskInfo.watchface, diskInfo.music, diskInfo.system)
})