Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Coping0606
Docs
提交
6ec796f1
D
Docs
项目概览
Coping0606
/
Docs
与 Fork 源项目一致
Fork自
OpenHarmony / Docs
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6ec796f1
编写于
6月 27, 2022
作者:
W
wangbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
文档修改
Signed-off-by:
N
wangbo
<
wangbo448@huawei.com
>
上级
8de08c44
变更
5
展开全部
显示空白变更内容
内联
并排
Showing
5 changed file
with
633 addition
and
228 deletion
+633
-228
zh-cn/application-dev/reference/apis/js-apis-document.md
zh-cn/application-dev/reference/apis/js-apis-document.md
+21
-13
zh-cn/application-dev/reference/apis/js-apis-fileio.md
zh-cn/application-dev/reference/apis/js-apis-fileio.md
+92
-201
zh-cn/application-dev/reference/apis/js-apis-filemanager.md
zh-cn/application-dev/reference/apis/js-apis-filemanager.md
+13
-8
zh-cn/application-dev/reference/apis/js-apis-securityLabel.md
...n/application-dev/reference/apis/js-apis-securityLabel.md
+181
-0
zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md
...lication-dev/reference/apis/js-apis-storage-statistics.md
+326
-6
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-document.md
浏览文件 @
6ec796f1
...
...
@@ -12,7 +12,7 @@ import document from '@ohos.document';
## document.choose
choose(type:string[]): Promise
<
string
>
choose(type
s
:string[]): Promise
<
string
>
通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。
...
...
@@ -22,7 +22,7 @@ choose(type:string[]): Promise<string>
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------------------- |
| type | string[] | 否 | 限定文件选择的类型 |
| type
s
| string[] | 否 | 限定文件选择的类型 |
-
返回值:
...
...
@@ -33,7 +33,8 @@ choose(type:string[]): Promise<string>
-
示例:
```
js
await
document
.
choose
(
type
);
let
tpyes
=
[];
document
.
choose
(
types
);
```
## document.choose
...
...
@@ -52,13 +53,14 @@ choose(callback:AsyncCallback<string>): void
-
示例:
```
js
await
document
.
choose
(
function
(
err
,
uri
)
{
let
uri
=
""
;
document
.
choose
(
function
(
err
,
uri
)
{
//do something with uri
});
```
## document.choose
choose(type:string[], callback:AsyncCallback
<
string
>
): void
choose(type
s
:string[], callback:AsyncCallback
<
string
>
): void
通过文件管理器选择文件,异步返回文件URI,使用callback形式返回结果。
...
...
@@ -68,20 +70,22 @@ choose(type:string[], callback:AsyncCallback<string>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- |
| type
| string[] | 否 | 限定选择文件的类型 |
| type
s
| string[] | 否 | 限定选择文件的类型 |
| callback | AsyncCallback
<
string
>
| 是 | 异步获取对应文件URI(注:当前返回错误码) |
-
示例:
```
js
await
document
.
choose
(
type
,
function
(
err
,
uri
)
{
let
types
=
[];
let
uri
=
""
;
document
.
choose
(
types
,
function
(
err
,
uri
)
{
//do something with uri
});
```
## document.show
show(url:string, type:string):Promise
<
number
>
show(url:string, type
s
:string):Promise
<
number
>
异步打开URI对应的文件,使用promise形式返回结果。
...
...
@@ -92,7 +96,7 @@ show(url:string, type:string):Promise<number>
| 参数 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI |
| type | string | 是 | 待打开文件的类型 |
| type
s
| string | 是 | 待打开文件的类型 |
-
返回值:
...
...
@@ -103,12 +107,14 @@ show(url:string, type:string):Promise<number>
-
示例:
```
js
await
document
.
show
(
uri
,
type
);
let
types
=
""
;
let
uri
=
""
;
document
.
show
(
uri
,
types
);
```
## document.show
show(url:string, type:string, callback:AsyncCallback
<
void
>
): void
show(url:string, type
s
:string, callback:AsyncCallback
<
void
>
): void
异步打开URI对应的文件,使用callback形式返回结果。
...
...
@@ -119,13 +125,15 @@ show(url:string, type:string, callback:AsyncCallback<void>): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI |
| type | string | 是 | 待打开文件的类型 |
| type
s
| string | 是 | 待打开文件的类型 |
| callback | AsyncCallback
<
void
>
| 是 | 异步打开uri对应文件(注:当前返回错误码) |
-
示例:
```
js
await
document
.
show
(
uri
,
type
,
function
(
err
)
{
let
types
=
""
;
let
uri
=
""
;
document
.
show
(
uri
,
types
,
function
(
err
)
{
//do something
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-fileio.md
浏览文件 @
6ec796f1
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-filemanager.md
浏览文件 @
6ec796f1
...
...
@@ -111,7 +111,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
```
js
// 获取目录下所有文件
// 通过listFile、getRoot获取的文件uri
let
media_path
=
file
.
path
let
media_path
=
""
filemanager
.
listFile
(
media_path
,
"
file
"
)
.
then
((
fileInfo
)
=>
{
if
(
Array
.
isArray
(
fileInfo
))
{
...
...
@@ -120,6 +120,9 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
}
}
}).
catch
((
err
)
=>
{
console
.
log
(
err
)
});
```
...
...
@@ -152,7 +155,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
```
js
// 通过listFile、getRoot获取的文件path
let
fileInfos
=
await
filemanager
.
getRoot
();
let
fileInfos
=
filemanager
.
getRoot
();
let
media_path
=
""
;
for
(
let
i
=
0
;
i
<
fileInfos
.
length
;
i
++
)
{
if
(
fileInfos
[
i
].
name
==
"
image_album
"
)
{
...
...
@@ -197,7 +200,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
| 类型 | 说明 |
| --- | -- |
|
Promise
<
string
>
| 文件uri |
|
string
| 文件uri |
-
异常
| 错误名称 | 错误类型 | 错误码 |说明 |
...
...
@@ -211,7 +214,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
```
js
// 创建文件,返回文件uri
let
media_path
=
file
.
uri
// 通过listFile、getRoot获取的文件uri
let
media_path
=
""
// 通过listFile、getRoot获取的文件uri
let
name
=
"
xxx.jpg
"
// 待保存文件的后缀
filemanager
.
createFile
(
media_path
,
name
).
then
((
uri
)
=>
{
// 返回uri给应用
...
...
@@ -252,13 +255,15 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
```
js
// 创建文件,返回文件uri
// 通过listFile、getRoot获取的文件uri
let
media_path
=
file
.
path
let
media_path
=
""
// 待保存文件的后缀
let
name
=
"
xxx.jpg
"
filemanager
.
createFile
(
media_path
,
name
,
(
err
,
uri
)
=>
{
let
dev
=
""
;
filemanager
.
createFile
(
media_path
,
name
,
{
DevInfo
:
dev
},
function
(
err
,
uri
)
{
// 返回uri给应用
console
.
log
(
"
file uri:
"
+
uri
);
});
```
## FileInfo
...
...
zh-cn/application-dev/reference/apis/js-apis-securityLabel.md
0 → 100644
浏览文件 @
6ec796f1
# 数据标签
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件数据安全等级的相关功能:向应用程序提供查询、设置文件数据安全等级的JS接口。
## 导入模块
```
js
import
securityLabel
from
'
@ohos.securityLabel
'
;
```
## 使用说明
使用该功能模块对文件/目录进行操作前,需要先获取其应用沙箱路径,获取方式及其接口用法请参考:
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
let
path
=
context
.
getFilesDir
();
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string):Promise
<
void
>
以异步方法设置数据标签,以promise形式返回结果。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
**返回值:**
| 类型 | 说明 |
| ------------------- | ---------------- |
| Promise
<
void
>
| Promise实例,用于异步获取结果。本调用将返回空值。|
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
setSecurityLabel
(
path
,
dataLevel
).
then
(
function
(){
console
.
info
(
"
setSecurityLabel successfully
"
);
}).
catch
(
function
(
error
){
console
.
info
(
"
setSecurityLabel failed with error:
"
+
error
);
});
```
## securityLabel.setSecurityLabel
setSecurityLabel(path:string, dataLevel:string, callback: AsyncCallback
<
void
>
):void
以异步方法设置数据标签,以callback形式返回结果。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------- | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
| callback | AsyncCallback
<
void
>
| 是 | 是否设置数据标签之后的回调 |
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
setSecurityLabel
(
path
,
dataLevel
,
function
(
error
){
console
.
info
(
"
setSecurityLabel:
"
+
JSON
.
stringify
(
error
));
});
```
## securityLabel.setSecurityLabelSync
setSecurityLabelSync(path:string, dataLevel:string):void
以同步方法设置数据标签。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | -------------------------------------------- |
| path | string | 是 | 文件路径 |
| dataLevel | string | 是 | 文件等级属性,只支持"s0","s1","s2","s3","s4" |
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
setSecurityLabelSync
(
path
,
dataLevel
);
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string):Promise
<
string
>
异步方法获取数据标签,以promise形式返回结果。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------- |
| path | string | 是 | 文件路径 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------ |
| Promise
<
string
>
| 返回数据标签 |
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
getSecurityLabel
(
path
).
then
(
function
(
dataLevel
){
console
.
log
(
"
getSecurityLabel successfully:
"
+
dataLevel
);
}).
catch
(
function
(
error
){
console
.
log
(
"
getSecurityLabel failed with error:
"
+
error
);
});
```
## securityLabel.getSecurityLabel
getSecurityLabel(path:string, callback:AsyncCallback
<
string
>
): void
异步方法获取数据标签,以callback形式返回结果。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | -------------------------- |
| path | string | 是 | 文件路径 |
| callback | AsyncCallback
<
string
>
| 是 | 异步获取数据标签之后的回调 |
**示例:**
```
js
let
dataLevel
=
"
s4
"
;
securityLabel
.
getSecurityLabel
(
path
,
function
(
error
,
dataLevel
){
console
.
log
(
"
getSecurityLabel successfully:
"
+
dataLevel
);
});
```
## securityLabel.getSecurityLabelSync
getSecurityLabelSync(path:string):string
以同步方法获取数据标签。
**系统能力**
:SystemCapability.FileManagement.File.DistributedFile
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------- |
| path | string | 是 | 文件路径 |
**返回值:**
| 类型 | 说明 |
| ------ | ------------ |
| string | 返回数据标签 |
**示例:**
```
js
let
result
=
securityLabel
.
getSecurityLabelSync
(
path
);
console
.
log
(
"
getSecurityLabel successfully:
"
+
result
);
```
zh-cn/application-dev/reference/apis/js-apis-storage-statistics.md
浏览文件 @
6ec796f1
...
...
@@ -4,14 +4,13 @@
>
> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
> - 本模块接口为系统接口,三方应用不支持调用。
该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
## 导入模块
```
js
import
storage
s
tatistics
from
"
@ohos.storageStatistics
"
;
import
storage
S
tatistics
from
"
@ohos.storageStatistics
"
;
```
## storagestatistics.getTotalSizeOfVolume
...
...
@@ -20,8 +19,12 @@ getTotalSizeOfVolume(volumeUuid: string): Promise<number>
异步获取指定卷的总空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
...
...
@@ -51,8 +54,12 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):v
异步获取指定卷的总空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
...
...
@@ -78,8 +85,12 @@ getFreeSizeOfVolume(volumeUuid: string): Promise<number>
异步获取指定卷的可用空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
...
...
@@ -110,8 +121,12 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):vo
异步获取指定卷的可用空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
...
...
@@ -135,8 +150,12 @@ getBundleStats(packageName: string): Promise<BundleStats>
异步获取应用存储数据,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
...
...
@@ -166,8 +185,12 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>)
异步获取应用存储数据,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
...
...
@@ -185,14 +208,311 @@ getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>)
});
```
## storagestatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(): Promise
<BundleStats>
第三方应用异步获取占用空间,以promise方式返回。
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
-
返回值
| 类型 | 说明 |
| ------------------------------------------ | -------------------------- |
| Promise
<
[Bundlestats](#bundlestats)
>
| 返回指定卷上的应用存储状态 |
-
示例
```
js
let
bundleStats
=
storageStatistics
.
getCurrentBundleStats
();
console
.
info
(
"
getCurrentBundleStats successfully:
"
+
JSON
.
stringify
(
bundleStats
));
```
## storagestatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(callback: AsyncCallback
<BundleStats>
): void
第三方应用异步获取占用空间,以callback方式返回。
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| callback | callback:AsyncCallback
<
[BundleStats](#bundlestats)
>
| 是 | 获取指定卷上的应用存储状态之后的回调 |
-
示例
```
js
storagestatistics
.
getCurrentBundleStats
(
function
(
error
,
bundleStats
){
// do something
console
.
info
(
"
getCurrentBundleStats successfully:
"
+
JSON
.
stringify
(
bundleStats
));
});
```
## BundleStats<sup>9+</sup>
**系统能力**
:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。
### 属性
-
属性
| 名称 | 类型 | 说明 |
| --------- | ------ | -------------- |
| appSize | number | app数据大小 |
| cacheSize | number | 缓存数据大小 |
| dataSize | number | 应用总数据大小 |
## storagestatistics.getTotalSize<sup>9+</sup>
getTotalSize(): Promise
<number>
获取内卡的总空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
返回值
| 类型 | 说明 |
| --------------------- | ------------------ |
| Promise
<
number
>
| 返回内卡的总空间大小 |
-
示例
```
js
let
number
=
storageStatistics
.
getTotalSize
();
console
.
info
(
"
getTotalSize successfully:
"
+
JSON
.
stringify
(
number
));
```
## storagestatistics.getTotalSize<sup>9+</sup>
getTotalSize(callback: AsyncCallback
<number>
): void
获取内卡的总空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------ |
| callback | callback:AsyncCallback
<
number
>
| 是 | 获取内卡的总空间大小之后的回调 |
-
示例
```
js
storagestatistics
.
getTotalSize
(
function
(
error
,
number
){
// do something
console
.
info
(
"
getTotalSize successfully:
"
+
JSON
.
stringify
(
number
));
});
```
## storagestatistics.getFreeSize<sup>9+</sup>
getFreeSize(): Promise
<number>
获取内卡的可用空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
返回值
| 类型 | 说明 |
| --------------------- | ------------------ |
| Promise
<
number
>
| 返回内卡的可用空间大小 |
-
示例
```
js
let
number
=
storageStatistics
.
getFreeSize
();
console
.
info
(
"
getFreeSize successfully:
"
+
JSON
.
stringify
(
number
));
```
## storagestatistics.getFreeSize<sup>9+</sup>
getFreeSize(callback: AsyncCallback
<number>
): void
获取内卡的可用空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------- |
| callback | callback:AsyncCallback
<
number
>
| 是 | 获取内卡的可用空间大小之后的回调 |
-
示例
```
js
storagestatistics
.
getFreeSize
(
function
(
error
,
number
){
// do something
console
.
info
(
"
getFreeSize successfully:
"
+
JSON
.
stringify
(
number
));
});
```
## storagestatistics.getSystemSize<sup>9+</sup>
getSystemSize(): Promise
<
number
>
异步获取系统空间大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
返回值
| 类型 | 说明 |
| --------------------- | ---------------- |
| Promise
<
number
>
| 返回系统空间大小 |
-
示例
```
js
storagestatistics
.
getSystemSize
().
then
(
function
(
number
){
console
.
info
(
"
getSystemSize successfully:
"
+
number
);
}).
catch
(
function
(
err
){
console
.
info
(
"
getSystemSize failed with error:
"
+
err
);
});
```
## storagestatistics.getSystemSize<sup>9+</sup>
getSystemSize(callback:AsyncCallback
<
number
>
):void
异步获取系统空间大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | callback:AsyncCallback
<
number
>
| 是 | 获取系统空间大小之后的回调 |
-
示例
```
js
storagestatistics
.
getSystemSize
(
function
(
error
,
number
){
// do something
console
.
info
(
"
getSystemSize successfully:
"
+
number
);
});
```
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: string): Promise
<
StorageStats
>
异步获取用户各类别数据大小,以promise方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- |
| userId | string | 否 | 用户id
<br/>
确认当前用户:
<br/>
-
有值:表示指定用户。
<br/>
-
无值:表示当前用户。|
-
返回值
| 类型 | 说明 |
| --------------------- | ---------------- |
| Promise
<
[StorageStats](#StorageStats)
>
| 返回各类别数据大小 |
-
示例
```
js
let
userId
=
""
;
storagestatistics
.
getUserStorageStats
(
userId
).
then
(
function
(
StorageStats
){
console
.
info
(
"
getUserStorageStats successfully:
"
+
JSON
.
stringify
(
StorageStats
));
}).
catch
(
function
(
err
){
console
.
info
(
"
getUserStorageStats failed with error:
"
+
err
);
});
```
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId?: string, callback:AsyncCallback
<
StorageStats
>
):void
异步获取用户各类别数据大小,以callback方式返回。
**需要权限**
:ohos.permission.STORAGE_MANAGER
**系统能力**
:SystemCapability.FileManagement.StorageService.SpatialStatistics
**系统API**
:该接口为系统接口,三方应用不支持调用
-
参数
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| userId | string | 否 | 用户id
<br/>
确认当前用户:
<br/>
-
有值:表示指定用户。
<br/>
-
无值:表示当前用户。 |
| callback | callback:AsyncCallback
<
[StorageStats](#StorageStats)
>
| 是 | 返回各类别数据大小之后的回调 |
-
示例
```
js
let
userId
=
""
;
storagestatistics
.
getUserStorageStats
(
userId
,
function
(
error
,
StorageStats
){
// do something
console
.
info
(
"
getUserStorageStats successfully:
"
+
JSON
.
stringify
(
StorageStats
));
});
```
## StorageStats<sup>9+</sup>
**系统能力**
:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。
-
属性
| 名称 | 类型 | 说明 |
| --------- | ------ | -------------- |
| appSize
<sup>
9+
</sup>
| number | app数据大小 |
| cacheSize
<sup>
9+
</sup>
| number | 缓存数据大小 |
| dataSize
<sup>
9+
</sup>
| number | 应用总数据大小 |
\ No newline at end of file
| total | number | 内卡总空间大小 |
| audio | number | 音频数据大小 |
| video | number | 视频数据大小 |
| image | number | 图像数据大小 |
| file | number | 文件数据大小 |
| app | number | 应用数据大小 |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录