Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
e03390b7
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
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看板
未验证
提交
e03390b7
编写于
8月 30, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 30, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23460 文件相关ts示例代码适配ArkTs补充修改
Merge pull request !23460 from 冯俊青/master
上级
1344bf60
12bb7b2b
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
207 addition
and
148 deletion
+207
-148
zh-cn/application-dev/file-management/app-file-access.md
zh-cn/application-dev/file-management/app-file-access.md
+14
-15
zh-cn/application-dev/file-management/app-file-backup.md
zh-cn/application-dev/file-management/app-file-backup.md
+56
-37
zh-cn/application-dev/file-management/app-file-upload-download.md
...plication-dev/file-management/app-file-upload-download.md
+11
-5
zh-cn/application-dev/file-management/dev-user-file-manager.md
.../application-dev/file-management/dev-user-file-manager.md
+15
-7
zh-cn/application-dev/file-management/file-access-across-devices.md
...ication-dev/file-management/file-access-across-devices.md
+4
-2
zh-cn/application-dev/file-management/manage-external-storage.md
...pplication-dev/file-management/manage-external-storage.md
+1
-1
zh-cn/application-dev/file-management/save-user-file.md
zh-cn/application-dev/file-management/save-user-file.md
+11
-7
zh-cn/application-dev/file-management/select-user-file.md
zh-cn/application-dev/file-management/select-user-file.md
+1
-0
zh-cn/application-dev/file-management/share-app-file.md
zh-cn/application-dev/file-management/share-app-file.md
+4
-2
zh-cn/application-dev/reference/apis/js-apis-file-picker.md
zh-cn/application-dev/reference/apis/js-apis-file-picker.md
+90
-72
未找到文件。
zh-cn/application-dev/file-management/app-file-access.md
浏览文件 @
e03390b7
...
...
@@ -48,12 +48,12 @@ import fs from '@ohos.file.fs';
import
common
from
'
@ohos.app.ability.common
'
;
import
buffer
from
'
@ohos.buffer
'
;
createFile
()
{
// 获取应用文件路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
// 获取应用文件路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
// 新建并打开文件
function
createFile
()
{
// 新建并打开文件
let
file
=
fs
.
openSync
(
filesDir
+
'
/test.txt
'
,
fs
.
OpenMode
.
READ_WRITE
|
fs
.
OpenMode
.
CREATE
);
// 写入一段内容至文件
let
writeLen
=
fs
.
writeSync
(
file
.
fd
,
"
Try to write str.
"
);
...
...
@@ -77,11 +77,11 @@ createFile() {
import
fs
from
'
@ohos.file.fs
'
;
import
common
from
'
@ohos.app.ability.common
'
;
readWriteFile
()
{
// 获取应用文件路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
// 获取应用文件路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
function
readWriteFile
()
{
// 打开文件
let
srcFile
=
fs
.
openSync
(
filesDir
+
'
/test.txt
'
,
fs
.
OpenMode
.
READ_WRITE
);
let
destFile
=
fs
.
openSync
(
filesDir
+
'
/destFile.txt
'
,
fs
.
OpenMode
.
READ_WRITE
|
fs
.
OpenMode
.
CREATE
);
...
...
@@ -114,11 +114,11 @@ readWriteFile() {
import
fs
from
'
@ohos.file.fs
'
;
import
common
from
'
@ohos.app.ability.common
'
;
async
readWriteFileWithStream
()
{
// 获取应用文件路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
// 获取应用文件路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
async
readWriteFileWithStream
()
{
// 打开文件流
let
inputStream
=
fs
.
createStreamSync
(
filesDir
+
'
/test.txt
'
,
'
r+
'
);
let
outputStream
=
fs
.
createStreamSync
(
filesDir
+
'
/destFile.txt
'
,
"
w+
"
);
...
...
@@ -148,7 +148,6 @@ async readWriteFileWithStream() {
以下示例代码演示了如何查看文件列表:
```
ts
// 查看文件列表
import
fs
,
{
Filter
}
from
'
@ohos.file.fs
'
;
import
common
from
'
@ohos.app.ability.common
'
;
...
...
@@ -157,7 +156,7 @@ let context = getContext(this) as common.UIAbilityContext;
let
filesDir
=
context
.
filesDir
;
// 查看文件列表
getListFile
()
{
function
getListFile
()
{
let
filter
:
Filter
=
{
suffix
:
[
'
.png
'
,
'
.jpg
'
,
'
.txt
'
],
// 匹配文件后缀名为'.png','.jpg','.txt'
displayName
:
[
'
test%
'
],
// 匹配文件全名以'test'开头
...
...
zh-cn/application-dev/file-management/app-file-backup.md
浏览文件 @
e03390b7
...
...
@@ -33,16 +33,24 @@
调用
`backup.getLocalCapabilities()`
获取能力文件。
```
ts
import
backup
from
'
@ohos.file.backup
'
;
import
common
from
'
@ohos.app.ability.common
'
;
import
fs
from
'
@ohos.file.fs
'
;
// 获取应用文件路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
async
function
getLocalCapabilities
()
{
try
{
let
fileData
=
await
backup
.
getLocalCapabilities
();
console
.
info
(
'
getLocalCapabilities success
'
);
let
fpath
=
await
globalThis
.
context
.
filesDir
+
'
/localCapabilities.json
'
;
let
fpath
=
filesDir
+
'
/localCapabilities.json
'
;
fs
.
copyFileSync
(
fileData
.
fd
,
fpath
);
fs
.
closeSync
(
fileData
.
fd
);
}
catch
(
err
)
{
console
.
error
(
'
getLocalCapabilities failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
getLocalCapabilities failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -88,19 +96,21 @@
**示例**
```
ts
import
fs
from
'
@ohos.file.fs
'
;
import
backup
from
'
@ohos.file.backup
'
;
import
common
from
'
@ohos.app.ability.common
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
// 获取沙箱路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
// 创建SessionBackup类的实例用于备份数据
let
g_session
:
backup
.
SessionBackup
;
createSessionBackup
()
{
function
createSessionBackup
()
{
let
sessionBackup
=
new
backup
.
SessionBackup
({
onFileReady
:
(
err
:
BusinessError
,
file
:
backup
.
File
)
=>
{
if
(
err
)
{
console
.
info
(
'
onFileReady err:
'
+
err
);
console
.
info
(
'
onFileReady err:
'
+
JSON
.
stringify
(
err
)
);
}
try
{
let
bundlePath
=
filesDir
+
'
/
'
+
file
.
bundleName
;
...
...
@@ -116,21 +126,21 @@
},
onBundleBegin
:
(
err
:
BusinessError
,
bundleName
:
string
)
=>
{
if
(
err
)
{
console
.
info
(
'
onBundleBegin err:
'
+
err
);
console
.
info
(
'
onBundleBegin err:
'
+
JSON
.
stringify
(
err
)
);
}
else
{
console
.
info
(
'
onBundleBegin bundleName:
'
+
bundleName
);
}
},
onBundleEnd
:
(
err
:
BusinessError
,
bundleName
:
string
)
=>
{
if
(
err
)
{
console
.
info
(
'
onBundleEnd err:
'
+
err
);
console
.
info
(
'
onBundleEnd err:
'
+
JSON
.
stringify
(
err
)
);
}
else
{
console
.
info
(
'
onBundleEnd bundleName:
'
+
bundleName
);
}
},
onAllBundlesEnd
:
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
info
(
'
onAllBundlesEnd err:
'
+
err
);
console
.
info
(
'
onAllBundlesEnd err:
'
+
JSON
.
stringify
(
err
)
);
}
else
{
console
.
info
(
'
onAllBundlesEnd
'
);
}
...
...
@@ -141,8 +151,8 @@
});
return
sessionBackup
;
}
async
sessionBackup
()
{
async
function
sessionBackup
()
{
g_session
=
createSessionBackup
();
// 此处可根据backup.getLocalCapabilities()提供的能力文件,选择需要备份的应用
// 也可直接根据应用包名称进行备份
...
...
@@ -165,20 +175,22 @@
**示例**
```
ts
import
backup
from
'
@ohos.file.backup
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
// 创建SessionRestore类的实例用于恢复数据
let
g_session
:
backup
.
SessionRestore
;
async
publishFile
(
file
:
backup
.
File
)
{
async
function
publishFile
(
file
:
backup
.
File
)
{
await
g_session
.
publishFile
({
bundleName
:
file
.
bundleName
,
uri
:
file
.
uri
});
}
createSessionRestore
()
{
function
createSessionRestore
()
{
let
sessionRestore
=
new
backup
.
SessionRestore
({
onFileReady
:
(
err
:
BusinessError
,
file
:
backup
.
File
)
=>
{
if
(
err
)
{
console
.
info
(
'
onFileReady err:
'
+
err
);
console
.
info
(
'
onFileReady err:
'
+
JSON
.
stringify
(
err
)
);
}
// 此处开发者请根据实际场景待恢复文件存放位置进行调整 bundlePath
let
bundlePath
:
string
;
...
...
@@ -193,19 +205,19 @@
},
onBundleBegin
:
(
err
:
BusinessError
,
bundleName
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
'
onBundleBegin failed with err:
'
+
err
);
console
.
error
(
'
onBundleBegin failed with err:
'
+
JSON
.
stringify
(
err
)
);
}
console
.
info
(
'
onBundleBegin success
'
);
},
onBundleEnd
:
(
err
:
BusinessError
,
bundleName
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
'
onBundleEnd failed with err:
'
+
err
);
console
.
error
(
'
onBundleEnd failed with err:
'
+
JSON
.
stringify
(
err
)
);
}
console
.
info
(
'
onBundleEnd success
'
);
},
onAllBundlesEnd
:
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
onAllBundlesEnd failed with err:
'
+
err
);
console
.
error
(
'
onAllBundlesEnd failed with err:
'
+
JSON
.
stringify
(
err
)
);
}
console
.
info
(
'
onAllBundlesEnd success
'
);
},
...
...
@@ -215,16 +227,16 @@
});
return
sessionRestore
;
}
async
restore01
()
{
async
function
restore01
()
{
g_session
=
createSessionRestore
();
const
backup
Apps
:
string
[]
=
[
const
restore
Apps
:
string
[]
=
[
"
com.example.hiworld
"
,
]
// 能力文件的获取方式可以根据开发者实际场景进行调整。此处仅为请求示例
// 开发者也可以根据能力文件内容的结构示例,自行构造能力文件内容
let
fileData
=
await
backup
.
getLocalCapabilities
();
await
g_session
.
appendBundles
(
fileData
.
fd
,
backup
Apps
);
await
g_session
.
appendBundles
(
fileData
.
fd
,
restore
Apps
);
console
.
info
(
'
appendBundles success
'
);
// 添加需要恢复的应用成功后,请根据需要恢复的应用名称,调用getFileHandle接口获取待恢复应用数文件的文件句柄
// 应用待恢复数据文件数请依据实际备份文件个数为准,此处仅为请求示例
...
...
@@ -251,21 +263,28 @@
**示例**
```
ts
import
backup
from
'
@ohos.file.backup
'
;
import
common
from
'
@ohos.app.ability.common
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
// 获取沙箱路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
let
filesDir
=
context
.
filesDir
;
// 创建SessionRestore类的实例用于恢复数据
let
g_session
:
backup
.
SessionRestore
;
async
publishFile
(
f
ile
)
{
async
function
publishFile
(
file
:
backup
.
F
ile
)
{
await
g_session
.
publishFile
({
bundleName
:
file
.
bundleName
,
uri
:
file
.
uri
});
}
createSessionRestore
()
{
function
createSessionRestore
()
{
let
sessionRestore
=
new
backup
.
SessionRestore
({
onFileReady
:
(
err
:
BusinessError
,
file
:
backup
.
File
)
=>
{
if
(
err
)
{
console
.
info
(
'
onFileReady err:
'
+
err
);
}
if
(
err
)
{
console
.
info
(
'
onFileReady err:
'
+
JSON
.
stringify
(
err
)
);
}
let
bundlePath
:
string
;
if
(
file
.
uri
==
"
/data/storage/el2/restore/bundle.hap
"
)
{
...
...
@@ -284,19 +303,19 @@
},
onBundleBegin
:
(
err
:
BusinessError
,
bundleName
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
'
onBundleBegin failed with err:
'
+
err
);
console
.
error
(
'
onBundleBegin failed with err:
'
+
JSON
.
stringify
(
err
)
);
}
console
.
info
(
'
onBundleBegin success
'
);
},
onBundleEnd
:
(
err
:
BusinessError
,
bundleName
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
'
onBundleEnd failed with err:
'
+
err
);
console
.
error
(
'
onBundleEnd failed with err:
'
+
JSON
.
stringify
(
err
)
);
}
console
.
info
(
'
onBundleEnd success
'
);
},
onAllBundlesEnd
:
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
onAllBundlesEnd failed with err:
'
+
err
);
console
.
error
(
'
onAllBundlesEnd failed with err:
'
+
JSON
.
stringify
(
err
)
);
}
console
.
info
(
'
onAllBundlesEnd success
'
);
},
...
...
@@ -306,28 +325,28 @@
});
return
sessionRestore
;
}
async
restore02
()
{
async
function
restore02
()
{
g_session
=
createSessionRestore
();
const
backup
Apps
:
string
[]
=
[
const
restore
Apps
:
string
[]
=
[
"
com.example.hiworld
"
,
]
let
fpath
=
await
globalThis
.
context
.
filesDir
+
'
/localCapabilities.json
'
;
let
file
=
fs
.
openSync
(
fpath
,
f
ileIO
.
OpenMode
.
CREATE
|
fileIO
.
OpenMode
.
READ_WRITE
);
let
fpath
=
filesDir
+
'
/localCapabilities.json
'
;
let
file
=
fs
.
openSync
(
fpath
,
f
s
.
OpenMode
.
CREATE
|
fs
.
OpenMode
.
READ_WRITE
);
let
content
=
"
{
\"
bundleInfos
\"
:[{
\"
allToBackup
\"
: false,
\"
extensionName
\"
:
\"\"
,
"
+
"
\"
name
\"
:
\"
cn.openharmony.inputmethodchoosedialog
\"
,
\"
needToInstall
\"
: true,
\"
spaceOccupied
\"
: 0,
"
+
"
\"
versionCode
\"
: 1000000,
\"
versionName
\"
:
\"
1.0.0
\"
}],
\"
deviceType
\"
:
\"
default
\"
,
\"
systemFullName
\"
:
\"
OpenHarmony-4.0.6.2(Canary1)
\"
}
"
;
fs
.
writeSync
(
file
.
fd
,
content
);
fs
.
fsyncSync
(
file
.
fd
);
await
g_session
.
appendBundles
(
file
.
fd
,
backup
Apps
);
await
g_session
.
appendBundles
(
file
.
fd
,
restore
Apps
);
console
.
info
(
'
appendBundles success
'
);
// 开发者需要请求安装应用的文件句柄
await
g_session
.
getFileHandle
({
bundleName
:
restoreApps
[
0
],
uri
:
"
/data/storage/el2/restore/bundle.hap
"
});
await
g_session
.
getFileHandle
({
bundleName
:
restoreApps
[
0
],
uri
:
"
manage.json
"
...
...
zh-cn/application-dev/file-management/app-file-upload-download.md
浏览文件 @
e03390b7
...
...
@@ -31,16 +31,19 @@ fs.writeSync(file.fd, 'upload file test');
fs
.
closeSync
(
file
);
// 上传任务配置项
let
header
=
new
Map
<
Object
,
string
>
();
header
.
set
(
'
key1
'
,
'
value1
'
);
header
.
set
(
'
key2
'
,
'
value2
'
);
let
files
:
Array
<
request
.
File
>
=
[
{
filename
:
'
test.txt
'
,
name
:
'
test
'
,
uri
:
'
internal://cache/test.txt
'
,
type
:
'
txt
'
}
]
let
data
:
request
.
RequestData
=
{
name
:
'
name
'
,
value
:
'
value
'
}
;
let
data
:
Array
<
request
.
RequestData
>
=
[{
name
:
'
name
'
,
value
:
'
value
'
}]
;
let
uploadConfig
:
request
.
UploadConfig
=
{
url
:
'
https://xxx
'
,
header
:
{
key1
:
'
value1
'
,
key2
:
'
value2
'
}
,
header
:
header
,
method
:
'
POST
'
,
files
:
files
,
data
:
[
data
]
data
:
data
}
// 将本地应用文件上传至网络服务器
...
...
@@ -56,7 +59,8 @@ try {
.
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Invoke uploadFile failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
})
}
catch
(
err
)
{
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
`Invoke uploadFile failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
```
...
...
@@ -80,6 +84,7 @@ import common from '@ohos.app.ability.common';
import
fs
from
'
@ohos.file.fs
'
;
import
request
from
'
@ohos.request
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
import
buffer
from
'
@ohos.buffer
'
;
// 获取应用文件路径
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
...
...
@@ -102,7 +107,8 @@ try {
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Invoke downloadTask failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
}
catch
(
err
)
{
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
`Invoke downloadFile failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
```
zh-cn/application-dev/file-management/dev-user-file-manager.md
浏览文件 @
e03390b7
...
...
@@ -23,6 +23,7 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以
import
fileAccess
from
'
@ohos.file.fileAccess
'
;
import
fileExtensionInfo
from
'
@ohos.file.fileExtensionInfo
'
;
import
{
Filter
}
from
'
@ohos.file.fs
'
;
import
common
from
'
@ohos.app.ability.common
'
;
```
其中fileAccess提供了文件基础操作的API,fileExtensionInfo提供了应用开发的关键结构体。
...
...
@@ -33,11 +34,14 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以
在文件访问框架中,使用RootInfo用于表示设备的属性信息。以下示例可以获取所有设备的RootInfo。
```
ts
// 获取应用上下文
let
context
=
getContext
(
this
)
as
common
.
UIAbilityContext
;
// 创建连接系统内所有文件管理服务端的helper对象
let
fileAccessHelperAllServer
:
fileAccess
.
FileAccessHelper
;
createFileAccessHelper
()
{
function
createFileAccessHelper
()
{
try
{
// this.context是EntryAbility传过来的Context
fileAccessHelperAllServer
=
fileAccess
.
createFileAccessHelper
(
this
.
context
);
fileAccessHelperAllServer
=
fileAccess
.
createFileAccessHelper
(
context
);
if
(
!
fileAccessHelperAllServer
)
{
console
.
error
(
"
createFileAccessHelper interface returns an undefined object
"
);
}
...
...
@@ -45,7 +49,7 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以
console
.
error
(
"
createFileAccessHelper failed, errCode:
"
+
error
.
code
+
"
, errMessage:
"
+
error
.
message
);
}
}
async
getRoots
()
{
async
function
getRoots
()
{
let
rootIterator
:
fileAccess
.
RootIterator
;
let
rootInfos
:
fileAccess
.
RootInfo
[]
=
[];
let
isDone
:
boolean
=
false
;
...
...
@@ -62,7 +66,8 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以
if
(
!
isDone
)
rootInfos
.
push
(
result
.
value
);
}
}
catch
(
error
)
{
}
catch
(
err
)
{
let
error
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
getRoots failed, errCode:
"
+
error
.
code
+
"
, errMessage:
"
+
error
.
message
);
}
}
...
...
@@ -93,7 +98,8 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以
if
(
!
isDone
)
fileInfos
.
push
(
result
.
value
);
}
}
catch
(
error
)
{
}
catch
(
err
)
{
let
error
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
listFile failed, errCode:
"
+
error
.
code
+
"
, errMessage:
"
+
error
.
message
);
}
...
...
@@ -116,7 +122,8 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以
if
(
!
isDone
)
subFileInfos
.
push
(
result
.
value
);
}
}
catch
(
error
)
{
}
catch
(
err
)
{
let
error
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
listFile failed, errCode:
"
+
error
.
code
+
"
, errMessage:
"
+
error
.
message
);
}
```
...
...
@@ -140,7 +147,8 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以
return
;
}
console
.
info
(
"
createFile sucess, fileUri:
"
+
JSON
.
stringify
(
fileUri
));
}
catch
(
error
)
{
}
catch
(
err
)
{
let
error
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
"
createFile failed, errCode:
"
+
error
.
code
+
"
, errMessage:
"
+
error
.
message
);
};
```
zh-cn/application-dev/file-management/file-access-across-devices.md
浏览文件 @
e03390b7
...
...
@@ -29,7 +29,8 @@
fs
.
writeSync
(
file
.
fd
,
'
content
'
);
// 关闭文件
fs
.
closeSync
(
file
.
fd
);
}
catch
(
err
)
{
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
`Failed to openSync / writeSync / closeSync. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
}
```
...
...
@@ -58,7 +59,8 @@
// 打印读取到的文件数据
let
buf
=
buffer
.
from
(
arrayBuffer
,
0
,
num
);
console
.
info
(
'
read result:
'
+
buf
.
toString
());
}
catch
(
err
)
{
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
`Failed to openSync / readSync. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
}
```
zh-cn/application-dev/file-management/manage-external-storage.md
浏览文件 @
e03390b7
...
...
@@ -78,7 +78,7 @@
let
volId
:
string
=
data
.
parameters
.
id
;
volumeManager
.
getVolumeById
(
volId
,
(
error
:
BusinessError
,
vol
:
volumeManager
.
Volume
)
=>
{
if
(
error
)
{
console
.
error
(
'
volumeManager getVolumeById failed
'
);
console
.
error
(
'
volumeManager getVolumeById failed
for
'
+
JSON
.
stringify
(
error
)
);
}
else
{
console
.
info
(
'
volumeManager getVolumeById successfully, the volume state is
'
+
vol
.
state
);
}
...
...
zh-cn/application-dev/file-management/save-user-file.md
浏览文件 @
e03390b7
...
...
@@ -30,7 +30,7 @@ save接口会将文件保存在文件管理器,而不是图库。
let
phAccessHelper
=
photoAccessHelper
.
getPhotoAccessHelper
(
context
);
let
pixelmapArrayBuffer
:
ArrayBuffer
;
async
getPixelmap
()
{
async
function
getPixelmap
()
{
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
...
...
@@ -48,10 +48,11 @@ save接口会将文件保存在文件管理器,而不是图库。
pixelmapArrayBuffer
=
readBuffer
;
})
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
[picker] getThumbnail failed with error:
'
+
err
);
console
.
error
(
'
[picker] getThumbnail failed with error:
'
+
JSON
.
stringify
(
err
)
);
});
}
catch
(
error
)
{
console
.
error
(
'
[picker] getThumbnail error =
'
+
error
);
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
[picker] getThumbnail error =
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -74,11 +75,13 @@ save接口会将文件保存在文件管理器,而不是图库。
uris
=
photoSaveResult
;
console
.
info
(
'
photoViewPicker.save to file succeed and uris are:
'
+
uris
);
}
}
catch
(
err
)
{
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
`[picker] Invoke photoViewPicker.save failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
}
catch
(
error
)
{
console
.
info
(
"
[picker] photoViewPickerSave error =
"
+
error
);
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
info
(
"
[picker] photoViewPickerSave error =
"
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -88,14 +91,15 @@ save接口会将文件保存在文件管理器,而不是图库。
然后,通过fd使用
[
fs.write
](
../reference/apis/js-apis-file-fs.md#fswrite
)
接口对这个文件进行编辑修改,编辑修改完成后关闭fd。
```
ts
async
writeOnly
(
uri
:
string
)
{
async
function
writeOnly
(
uri
:
string
)
{
try
{
let
file
=
fs
.
openSync
(
uri
,
fs
.
OpenMode
.
WRITE_ONLY
);
let
writeLen
=
await
fs
.
write
(
file
.
fd
,
pixelmapArrayBuffer
);
fs
.
closeSync
(
file
);
console
.
info
(
"
[picker] writeOnly writeLen =
"
+
writeLen
);
}
catch
(
error
)
{
console
.
info
(
"
[picker] writeOnly error:
"
+
error
);
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
info
(
"
[picker] writeOnly error:
"
+
JSON
.
stringify
(
err
));
}
}
```
...
...
zh-cn/application-dev/file-management/select-user-file.md
浏览文件 @
e03390b7
...
...
@@ -124,6 +124,7 @@
// 获取到文档文件的文件名称
let
file_name_list
=
result
.
want
.
parameters
.
file_name_list
;
}
catch
(
err
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
`Invoke documentViewPicker.select failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
```
...
...
zh-cn/application-dev/file-management/share-app-file.md
浏览文件 @
e03390b7
...
...
@@ -138,11 +138,13 @@ function getShareFile() {
// 根据需要对被分享文件的URI进行相应操作。例如读写的方式打开URI获取file对象
let
file
=
fs
.
openSync
(
uri
,
fs
.
OpenMode
.
READ_WRITE
);
console
.
info
(
'
open file successfully!
'
);
}
catch
(
error
)
{
}
catch
(
err
)
{
let
error
:
BusinessError
=
err
as
BusinessError
;
console
.
error
(
`Invoke openSync failed, code is
${
error
.
code
}
, message is
${
error
.
message
}
`
);
}
}
catch
(
error
)
{
console
.
error
(
`Invoke openSync failed, code is
${
error
.
code
}
, message is
${
error
.
message
}
`
);
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
`Invoke openSync failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
}
```
zh-cn/application-dev/reference/apis/js-apis-file-picker.md
浏览文件 @
e03390b7
...
...
@@ -52,7 +52,7 @@ select(option?: PhotoSelectOptions) : Promise<PhotoSelectResult>
**示例:**
```
ts
async
example01
()
{
async
function
example01
()
{
try
{
let
PhotoSelectOptions
=
new
picker
.
PhotoSelectOptions
();
PhotoSelectOptions
.
MIMEType
=
picker
.
PhotoViewMIMETypes
.
IMAGE_TYPE
;
...
...
@@ -61,10 +61,11 @@ async example01() {
photoPicker
.
select
(
PhotoSelectOptions
).
then
((
PhotoSelectResult
:
picker
.
PhotoSelectResult
)
=>
{
console
.
info
(
'
PhotoViewPicker.select successfully, PhotoSelectResult uri:
'
+
JSON
.
stringify
(
PhotoSelectResult
));
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
PhotoViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
PhotoViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
});
}
catch
(
err
)
{
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -87,7 +88,7 @@ select(option: PhotoSelectOptions, callback: AsyncCallback<PhotoSelectResult&
**示例:**
```
ts
async
example02
()
{
async
function
example02
()
{
try
{
let
PhotoSelectOptions
=
new
picker
.
PhotoSelectOptions
();
PhotoSelectOptions
.
MIMEType
=
picker
.
PhotoViewMIMETypes
.
IMAGE_TYPE
;
...
...
@@ -95,13 +96,14 @@ async example02() {
let
photoPicker
=
new
picker
.
PhotoViewPicker
();
photoPicker
.
select
(
PhotoSelectOptions
,
(
err
:
BusinessError
,
PhotoSelectResult
:
picker
.
PhotoSelectResult
)
=>
{
if
(
err
)
{
console
.
error
(
'
PhotoViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
PhotoViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
PhotoViewPicker.select successfully, PhotoSelectResult uri:
'
+
JSON
.
stringify
(
PhotoSelectResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -123,18 +125,19 @@ select(callback: AsyncCallback<PhotoSelectResult>) : void
**示例:**
```
ts
async
example03
()
{
async
function
example03
()
{
try
{
let
photoPicker
=
new
picker
.
PhotoViewPicker
();
photoPicker
.
select
((
err
:
BusinessError
,
PhotoSelectResult
:
picker
.
PhotoSelectResult
)
=>
{
if
(
err
)
{
console
.
error
(
'
PhotoViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
PhotoViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
PhotoViewPicker.select successfully, PhotoSelectResult uri:
'
+
JSON
.
stringify
(
PhotoSelectResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -162,7 +165,7 @@ save(option?: PhotoSaveOptions) : Promise<Array<string>>
**示例:**
```
ts
async
example04
()
{
async
function
example04
()
{
try
{
let
PhotoSaveOptions
=
new
picker
.
PhotoSaveOptions
();
PhotoSaveOptions
.
newFileNames
=
[
'
PhotoViewPicker01.jpg
'
,
'
PhotoViewPicker01.mp4
'
];
...
...
@@ -170,10 +173,11 @@ async example04() {
photoPicker
.
save
(
PhotoSaveOptions
).
then
((
PhotoSaveResult
:
Array
<
string
>
)
=>
{
console
.
info
(
'
PhotoViewPicker.save successfully, PhotoSaveResult uri:
'
+
JSON
.
stringify
(
PhotoSaveResult
));
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
PhotoViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
PhotoViewPicker.save failed with err:
'
+
JSON
.
stringify
(
err
)
);
});
}
catch
(
err
)
{
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -196,20 +200,21 @@ save(option: PhotoSaveOptions, callback: AsyncCallback<Array<string>>
**示例:**
```
ts
async
example05
()
{
async
function
example05
()
{
try
{
let
PhotoSaveOptions
=
new
picker
.
PhotoSaveOptions
();
PhotoSaveOptions
.
newFileNames
=
[
'
PhotoViewPicker02.jpg
'
,
'
PhotoViewPicker02.mp4
'
];
let
photoPicker
=
new
picker
.
PhotoViewPicker
();
photoPicker
.
save
(
PhotoSaveOptions
,
(
err
:
BusinessError
,
PhotoSaveResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
PhotoViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
PhotoViewPicker.save failed with err:
'
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
PhotoViewPicker.save successfully, PhotoSaveResult uri:
'
+
JSON
.
stringify
(
PhotoSaveResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -231,18 +236,19 @@ save(callback: AsyncCallback<Array<string>>) : void
**示例:**
```
ts
async
example06
()
{
async
function
example06
()
{
try
{
let
photoPicker
=
new
picker
.
PhotoViewPicker
();
photoPicker
.
save
((
err
:
BusinessError
,
PhotoSaveResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
PhotoViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
PhotoViewPicker.save failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
PhotoViewPicker.save successfully, PhotoSaveResult uri:
'
+
JSON
.
stringify
(
PhotoSaveResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
PhotoViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -282,17 +288,18 @@ select(option?: DocumentSelectOptions) : Promise<Array<string>>
**示例:**
```
ts
async
example07
()
{
async
function
example07
()
{
try
{
let
DocumentSelectOptions
=
new
picker
.
DocumentSelectOptions
();
let
documentPicker
=
new
picker
.
DocumentViewPicker
();
documentPicker
.
select
(
DocumentSelectOptions
).
then
((
DocumentSelectResult
:
Array
<
string
>
)
=>
{
console
.
info
(
'
DocumentViewPicker.select successfully, DocumentSelectResult uri:
'
+
JSON
.
stringify
(
DocumentSelectResult
));
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
DocumentViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
DocumentViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
});
}
catch
(
err
)
{
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -315,19 +322,20 @@ select(option: DocumentSelectOptions, callback: AsyncCallback<Array<string
**示例:**
```
ts
async
example08
()
{
async
function
example08
()
{
try
{
let
DocumentSelectOptions
=
new
picker
.
DocumentSelectOptions
();
let
documentPicker
=
new
picker
.
DocumentViewPicker
();
documentPicker
.
select
(
DocumentSelectOptions
,
(
err
:
BusinessError
,
DocumentSelectResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
DocumentViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
DocumentViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
DocumentViewPicker.select successfully, DocumentSelectResult uri:
'
+
JSON
.
stringify
(
DocumentSelectResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -349,18 +357,19 @@ select(callback: AsyncCallback<Array<string>>) : void
**示例:**
```
ts
async
example09
()
{
async
function
example09
()
{
try
{
let
documentPicker
=
new
picker
.
DocumentViewPicker
();
documentPicker
.
select
((
err
:
BusinessError
,
DocumentSelectResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
DocumentViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
DocumentViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
DocumentViewPicker.select successfully, DocumentSelectResult uri:
'
+
JSON
.
stringify
(
DocumentSelectResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -389,7 +398,7 @@ save(option?: DocumentSaveOptions) : Promise<Array<string>>
**示例:**
```
ts
async
example10
()
{
async
function
example10
()
{
try
{
let
DocumentSaveOptions
=
new
picker
.
DocumentSaveOptions
();
DocumentSaveOptions
.
newFileNames
=
[
'
DocumentViewPicker01.txt
'
];
...
...
@@ -397,10 +406,11 @@ async example10() {
documentPicker
.
save
(
DocumentSaveOptions
).
then
((
DocumentSaveResult
:
Array
<
string
>
)
=>
{
console
.
info
(
'
DocumentViewPicker.save successfully, DocumentSaveResult uri:
'
+
JSON
.
stringify
(
DocumentSaveResult
));
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
DocumentViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
DocumentViewPicker.save failed with err:
'
+
JSON
.
stringify
(
err
)
);
});
}
catch
(
err
)
{
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -423,20 +433,21 @@ save(option: DocumentSaveOptions, callback: AsyncCallback<Array<string>
**示例:**
```
ts
async
example11
()
{
async
function
example11
()
{
try
{
let
DocumentSaveOptions
=
new
picker
.
DocumentSaveOptions
();
DocumentSaveOptions
.
newFileNames
=
[
'
DocumentViewPicker02.txt
'
];
let
documentPicker
=
new
picker
.
DocumentViewPicker
();
documentPicker
.
save
(
DocumentSaveOptions
,
(
err
:
BusinessError
,
DocumentSaveResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
DocumentViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
DocumentViewPicker.save failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
DocumentViewPicker.save successfully, DocumentSaveResult uri:
'
+
JSON
.
stringify
(
DocumentSaveResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -458,18 +469,19 @@ save(callback: AsyncCallback<Array<string>>) : void
**示例:**
```
ts
async
example12
()
{
async
function
example12
()
{
try
{
let
documentPicker
=
new
picker
.
DocumentViewPicker
();
documentPicker
.
save
((
err
:
BusinessError
,
DocumentSaveResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
DocumentViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
DocumentViewPicker.save failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
DocumentViewPicker.save successfully, DocumentSaveResult uri:
'
+
JSON
.
stringify
(
DocumentSaveResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
DocumentViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -509,17 +521,18 @@ select(option?: AudioSelectOptions) : Promise<Array<string>>
**示例:**
```
ts
async
example13
()
{
async
function
example13
()
{
try
{
let
AudioSelectOptions
=
new
picker
.
AudioSelectOptions
();
let
audioPicker
=
new
picker
.
AudioViewPicker
();
audioPicker
.
select
(
AudioSelectOptions
).
then
((
AudioSelectResult
:
Array
<
string
>
)
=>
{
console
.
info
(
'
AudioViewPicker.select successfully, AudioSelectResult uri:
'
+
JSON
.
stringify
(
AudioSelectResult
));
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
AudioViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
AudioViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
});
}
catch
(
err
)
{
console
.
error
(
'
AudioViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
AudioViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -542,19 +555,20 @@ select(option: AudioSelectOptions, callback: AsyncCallback<Array<string>
**示例:**
```
ts
async
example14
()
{
async
function
example14
()
{
try
{
let
AudioSelectOptions
=
new
picker
.
AudioSelectOptions
();
let
audioPicker
=
new
picker
.
AudioViewPicker
();
audioPicker
.
select
(
AudioSelectOptions
,
(
err
:
BusinessError
,
AudioSelectResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
AudioViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
AudioViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
AudioViewPicker.select successfully, AudioSelectResult uri:
'
+
JSON
.
stringify
(
AudioSelectResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
AudioViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
AudioViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -576,18 +590,19 @@ select(callback: AsyncCallback<Array<string>>) : void
**示例:**
```
ts
async
example15
()
{
async
function
example15
()
{
try
{
let
audioPicker
=
new
picker
.
AudioViewPicker
();
audioPicker
.
select
((
err
:
BusinessError
,
AudioSelectResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
AudioViewPicker.select failed with err:
'
+
err
);
console
.
error
(
'
AudioViewPicker.select failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
AudioViewPicker.select successfully, AudioSelectResult uri:
'
+
JSON
.
stringify
(
AudioSelectResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
AudioViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
AudioViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -615,7 +630,7 @@ save(option?: AudioSaveOptions) : Promise<Array<string>>
**示例:**
```
ts
async
example16
()
{
async
function
example16
()
{
try
{
let
AudioSaveOptions
=
new
picker
.
AudioSaveOptions
();
AudioSaveOptions
.
newFileNames
=
[
'
AudioViewPicker01.mp3
'
];
...
...
@@ -623,10 +638,11 @@ async example16() {
audioPicker
.
save
(
AudioSaveOptions
).
then
((
AudioSaveResult
:
Array
<
string
>
)
=>
{
console
.
info
(
'
AudioViewPicker.save successfully, AudioSaveResult uri:
'
+
JSON
.
stringify
(
AudioSaveResult
))
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
AudioViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
AudioViewPicker.save failed with err:
'
+
JSON
.
stringify
(
err
)
);
});
}
catch
(
err
)
{
console
.
error
(
'
AudioViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
AudioViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -649,20 +665,21 @@ save(option: AudioSaveOptions, callback: AsyncCallback<Array<string>>
**示例:**
```
ts
async
example17
()
{
async
function
example17
()
{
try
{
let
AudioSaveOptions
=
new
picker
.
AudioSaveOptions
();
AudioSaveOptions
.
newFileNames
=
[
'
AudioViewPicker02.mp3
'
];
let
audioPicker
=
new
picker
.
AudioViewPicker
();
audioPicker
.
save
(
AudioSaveOptions
,
(
err
:
BusinessError
,
AudioSaveResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
AudioViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
AudioViewPicker.save failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
AudioViewPicker.save successfully, AudioSaveResult uri:
'
+
JSON
.
stringify
(
AudioSaveResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
AudioViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
AudioViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
@@ -684,18 +701,19 @@ save(callback: AsyncCallback<Array<string>>) : void
**示例:**
```
ts
async
example18
()
{
async
function
example18
()
{
try
{
let
audioPicker
=
new
picker
.
AudioViewPicker
();
audioPicker
.
save
((
err
:
BusinessError
,
AudioSaveResult
:
Array
<
string
>
)
=>
{
if
(
err
)
{
console
.
error
(
'
AudioViewPicker.save failed with err:
'
+
err
);
console
.
error
(
'
AudioViewPicker.save failed with err:
'
+
JSON
.
stringify
(
err
)
);
return
;
}
console
.
info
(
'
AudioViewPicker.save successfully, AudioSaveResult uri:
'
+
JSON
.
stringify
(
AudioSaveResult
));
});
}
catch
(
err
)
{
console
.
error
(
'
AudioViewPicker failed with err:
'
+
err
);
}
catch
(
error
)
{
let
err
:
BusinessError
=
error
as
BusinessError
;
console
.
error
(
'
AudioViewPicker failed with err:
'
+
JSON
.
stringify
(
err
));
}
}
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录