Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2b89f7d0
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
2b89f7d0
编写于
2月 25, 2023
作者:
O
openharmony_ci
提交者:
Gitee
2月 25, 2023
浏览文件
操作
浏览文件
下载
差异文件
!15172 Indent format modified for monthly
Merge pull request !15172 from 胡伟奇/monthly
上级
d2e79ba4
59908c14
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
406 addition
and
407 deletion
+406
-407
zh-cn/application-dev/file-management/medialibrary-album-guidelines.md
...tion-dev/file-management/medialibrary-album-guidelines.md
+28
-28
zh-cn/application-dev/file-management/medialibrary-filepath-guidelines.md
...n-dev/file-management/medialibrary-filepath-guidelines.md
+127
-127
zh-cn/application-dev/file-management/medialibrary-overview.md
.../application-dev/file-management/medialibrary-overview.md
+58
-58
zh-cn/application-dev/file-management/medialibrary-resource-guidelines.md
...n-dev/file-management/medialibrary-resource-guidelines.md
+193
-194
未找到文件。
zh-cn/application-dev/file-management/medialibrary-album-guidelines.md
浏览文件 @
2b89f7d0
zh-cn/application-dev/file-management/medialibrary-filepath-guidelines.md
浏览文件 @
2b89f7d0
...
...
@@ -166,8 +166,8 @@ async function copySandbox2Public() {
1.
创建用于读写示例的文件。
```
ts
async
function
example
()
{
```
ts
async
function
example
()
{
let
mediaType
=
mediaLibrary
.
MediaType
.
FILE
;
let
DIR_DOCUMENTS
=
mediaLibrary
.
DirectoryType
.
DIR_DOCUMENTS
;
const
context
=
getContext
(
this
);
...
...
@@ -178,8 +178,8 @@ async function copySandbox2Public() {
}).
catch
((
err
)
=>
{
console
.
error
(
"
createAsset failed with error:
"
+
err
);
});
}
```
}
```
2.
使用open打开文件。
...
...
zh-cn/application-dev/file-management/medialibrary-overview.md
浏览文件 @
2b89f7d0
...
...
@@ -63,8 +63,8 @@ let media = mediaLibrary.getMediaLibrary(context);
1.
在配置文件module.json5中声明权限。在配置文件的“module”标签内,增加“requestPermissions”标签,标签内容请根据实际情况填写。标签说明可参考
[
访问控制(权限)开发指导
](
../security/accesstoken-guidelines.md
)
。
```
json
{
```
json
{
"module"
:
{
"requestPermissions"
:
[
{
...
...
@@ -72,7 +72,7 @@ let media = mediaLibrary.getMediaLibrary(context);
"reason"
:
"$string:reason"
,
"usedScene"
:
{
"abilities"
:
[
"Main
Ability"
"Entry
Ability"
],
"when"
:
"always"
}
...
...
@@ -82,7 +82,7 @@ let media = mediaLibrary.getMediaLibrary(context);
"reason"
:
"$string:reason"
,
"usedScene"
:
{
"abilities"
:
[
"Main
Ability"
"Entry
Ability"
],
"when"
:
"always"
}
...
...
@@ -92,23 +92,23 @@ let media = mediaLibrary.getMediaLibrary(context);
"reason"
:
"$string:reason"
,
"usedScene"
:
{
"abilities"
:
[
"Main
Ability"
"Entry
Ability"
],
"when"
:
"always"
}
}
]
}
}
```
}
```
2.
在Ability.ts中onWindowStageCreate里调用requestPermissionsFromUser进行权限校验,可以选择需要动态申请获取的权限自行添加相应代码
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
abilityAccessCtrl
,
{
Permissions
}
from
'
@ohos.abilityAccessCtrl
'
;
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
abilityAccessCtrl
,
{
Permissions
}
from
'
@ohos.abilityAccessCtrl
'
;
export
default
class
EntryAbility
extends
UIAbility
{
export
default
class
EntryAbility
extends
UIAbility
{
onWindowStageCreate
(
windowStage
)
{
let
list
:
Array
<
Permissions
>
=
[
'
ohos.permission.READ_MEDIA
'
,
'
ohos.permission.WRITE_MEDIA
'
];
let
permissionRequestResult
;
...
...
@@ -117,11 +117,11 @@ let media = mediaLibrary.getMediaLibrary(context);
if
(
err
)
{
console
.
error
(
'
requestPermissionsFromUserError:
'
+
JSON
.
stringify
(
err
));
}
else
{
permissionRequestResult
=
result
;
permissionRequestResult
=
result
;
console
.
info
(
'
permissionRequestResult:
'
+
JSON
.
stringify
(
permissionRequestResult
));
}
});
}
}
```
}
```
zh-cn/application-dev/file-management/medialibrary-resource-guidelines.md
浏览文件 @
2b89f7d0
...
...
@@ -134,7 +134,6 @@ selectionArgs:'myAlbum',具体相册名称。
```
ts
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
option
=
{
selections
:
fileKeyObj
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
myAlbum
'
],
...
...
@@ -169,24 +168,24 @@ async function example() {
1.
建立检索条件,用于获取目的相册实例。
```
ts
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
AlbumNoArgsFetchOp
=
{
```
ts
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
AlbumNoArgsFetchOp
=
{
selections
:
fileKeyObj
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
新建相册1
'
]
}
```
}
```
2.
建立检索条件,用于获取目的相册下的视频资源。
```
ts
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
videoType
=
mediaLibrary
.
MediaType
.
VIDEO
;
let
videoFetchOp
=
{
```
ts
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
videoType
=
mediaLibrary
.
MediaType
.
VIDEO
;
let
videoFetchOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
videoType
.
toString
()],
}
```
}
```
3.
通过Album.getFileAssets获取对应的资源。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录