外观
system.request 补充 API
约 329 字大约 1 分钟
2026-07-15
官网列出 download() 和 onDownloadComplete(),但遗漏了 download() 的两个字段。
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
share | Boolean | true | 下载文件是否按共享语义处理 |
onDownLoadNotify | Function | — | 进度通知,注意固件 ABI 中 Load 的大小写 |
进度回调参数:
{
result: number,
percent: number
}result 是底层下载进度状态/结果码,percent 是进度百分比;JIDL 没有给出 result 枚举,也没有规定百分比一定单调递增。UI 应把 percent 限制到 0–100,并允许重复通知。
request.download({
url: 'https://example.com/file.bin',
share: false,
onDownLoadNotify: ({ result, percent }) => {
console.log(result, percent)
},
success: ({ token }) => console.log(token)
})推荐进度处理
let lastPercent = 0
request.download({
url,
share: false,
onDownLoadNotify(info) {
if (!info || typeof info.percent !== 'number') return
lastPercent = Math.max(lastPercent, Math.min(100, info.percent))
updateProgress(lastPercent)
},
success({ token }) {
console.log('download token:', token)
},
fail(message, code) {
console.error('download failed:', code, message)
}
})share: true 是固件默认值,可能改变下载文件的可见范围或后续共享语义;处理敏感文件时显式设为 false。字段名必须严格写作 onDownLoadNotify,其中 DownLoad 的 L 大写是 ABI 的一部分。
进度通知不等同于下载完成,最终状态仍以 success/fail 及官网的 onDownloadComplete() 契约为准。
机型可用性
| Xiaomi Smart Band 10 Pro | Xiaomi Watch S4 41mm |
|---|---|
| ❌ | ✅ |