Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
61090577
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看板
提交
61090577
编写于
9月 05, 2023
作者:
S
sunshenshen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
接口文档告警修改
Signed-off-by:
N
sunshenshen
<
sunshenshen@huawei.com
>
上级
d1fb793b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
778 addition
and
764 deletion
+778
-764
zh-cn/application-dev/reference/apis/js-apis-photoAccessHelper.md
...plication-dev/reference/apis/js-apis-photoAccessHelper.md
+353
-352
zh-cn/application-dev/reference/apis/js-apis-userFileManager.md
...application-dev/reference/apis/js-apis-userFileManager.md
+425
-412
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-photoAccessHelper.md
浏览文件 @
61090577
...
...
@@ -87,8 +87,8 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getAssets
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
...
...
@@ -96,7 +96,7 @@ async function example() {
phAccessHelper
.
getAssets
(
fetchOptions
,
async
(
err
,
fetchResult
)
=>
{
if
(
fetchResult
!=
undefined
)
{
console
.
info
(
'
fetchResult success
'
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
if
(
photoAsset
!=
undefined
)
{
console
.
info
(
'
photoAsset.displayName :
'
+
photoAsset
.
displayName
);
}
...
...
@@ -144,16 +144,16 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getAssets
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
if
(
fetchResult
!=
undefined
)
{
console
.
info
(
'
fetchResult success
'
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
if
(
photoAsset
!=
undefined
)
{
console
.
info
(
'
photoAsset.displayName :
'
+
photoAsset
.
displayName
);
}
...
...
@@ -198,7 +198,7 @@ createAsset(displayName: string, callback: AsyncCallback<PhotoAsset>): voi
```
ts
async
function
example
()
{
console
.
info
(
'
createAssetDemo
'
);
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
phAccessHelper
.
createAsset
(
testFileName
,
(
err
,
photoAsset
)
=>
{
if
(
photoAsset
!=
undefined
)
{
console
.
info
(
'
createAsset file displayName
'
+
photoAsset
.
displayName
);
...
...
@@ -250,8 +250,8 @@ createAsset(displayName: string): Promise<PhotoAsset>;
async
function
example
()
{
console
.
info
(
'
createAssetDemo
'
);
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
photoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
console
.
info
(
'
createAsset file displayName
'
+
photoAsset
.
displayName
);
console
.
info
(
'
createAsset successfully
'
);
}
catch
(
err
)
{
...
...
@@ -295,8 +295,8 @@ createAsset(displayName: string, options: PhotoCreateOptions, callback: AsyncCal
```
ts
async
function
example
()
{
console
.
info
(
'
createAssetDemo
'
);
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
createOption
=
{
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
createOption
:
photoAccessHelper
.
PhotoCreateOptions
=
{
subtype
:
photoAccessHelper
.
PhotoSubtype
.
DEFAULT
}
phAccessHelper
.
createAsset
(
testFileName
,
createOption
,
(
err
,
photoAsset
)
=>
{
...
...
@@ -351,11 +351,11 @@ createAsset(displayName: string, options: PhotoCreateOptions): Promise<PhotoA
async
function
example
()
{
console
.
info
(
'
createAssetDemo
'
);
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
createOption
=
{
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
createOption
:
photoAccessHelper
.
PhotoCreateOptions
=
{
subtype
:
photoAccessHelper
.
PhotoSubtype
.
DEFAULT
}
let
photoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
,
createOption
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
,
createOption
);
console
.
info
(
'
createAsset file displayName
'
+
photoAsset
.
displayName
);
console
.
info
(
'
createAsset successfully
'
);
}
catch
(
err
)
{
...
...
@@ -396,9 +396,9 @@ createAsset(photoType: PhotoType, extension: string, options: CreateOptions, cal
```
ts
async
function
example
()
{
console
.
info
(
'
createAssetDemo
'
);
let
photoType
=
photoAccessHelper
.
PhotoType
.
IMAGE
;
let
extension
=
'
jpg
'
;
let
options
=
{
let
photoType
:
photoAccessHelper
.
PhotoType
=
photoAccessHelper
.
PhotoType
.
IMAGE
;
let
extension
:
string
=
'
jpg
'
;
let
options
:
photoAccessHelper
.
CreateOptions
=
{
title
:
'
testPhoto
'
}
phAccessHelper
.
createAsset
(
photoType
,
extension
,
options
,
(
err
,
uri
)
=>
{
...
...
@@ -443,8 +443,8 @@ createAsset(photoType: PhotoType, extension: string, callback: AsyncCallback<
```
ts
async
function
example
()
{
console
.
info
(
'
createAssetDemo
'
);
let
photoType
=
photoAccessHelper
.
PhotoType
.
IMAGE
;
let
extension
=
'
jpg
'
;
let
photoType
:
photoAccessHelper
.
PhotoType
=
photoAccessHelper
.
PhotoType
.
IMAGE
;
let
extension
:
string
=
'
jpg
'
;
phAccessHelper
.
createAsset
(
photoType
,
extension
,
(
err
,
uri
)
=>
{
if
(
uri
!=
undefined
)
{
console
.
info
(
'
createAsset uri
'
+
uri
);
...
...
@@ -494,12 +494,12 @@ createAsset(photoType: PhotoType, extension: string, options?: CreateOptions): P
async
function
example
()
{
console
.
info
(
'
createAssetDemo
'
);
try
{
let
photoType
=
photoAccessHelper
.
PhotoType
.
IMAGE
;
let
extension
=
'
jpg
'
;
let
options
=
{
let
photoType
:
photoAccessHelper
.
PhotoType
=
photoAccessHelper
.
PhotoType
.
IMAGE
;
let
extension
:
string
=
'
jpg
'
;
let
options
:
photoAccessHelper
.
CreateOptions
=
{
title
:
'
testPhoto
'
}
let
uri
=
await
phAccessHelper
.
createAsset
(
photoType
,
extension
,
options
);
let
uri
:
string
=
await
phAccessHelper
.
createAsset
(
photoType
,
extension
,
options
);
console
.
info
(
'
createAsset uri
'
+
uri
);
console
.
info
(
'
createAsset successfully
'
);
}
catch
(
err
)
{
...
...
@@ -547,7 +547,7 @@ createAlbum(name: string, callback: AsyncCallback<Album>): void;
```ts
async function example() {
console.info('createAlbumDemo');
let albumName = 'newAlbumName' + new Date().getTime();
let albumName
: string
= 'newAlbumName' + new Date().getTime();
phAccessHelper.createAlbum(albumName, (err, album) => {
if (err) {
console.error('createAlbumCallback failed with err: ' + err);
...
...
@@ -600,12 +600,14 @@ createAlbum(name: string): Promise<Album>;
**示例:**
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
createAlbumDemo
'
);
let
albumName
=
'
newAlbumName
'
+
new
Date
().
getTime
();
let
albumName
:
string
=
'
newAlbumName
'
+
new
Date
().
getTime
();
phAccessHelper
.
createAlbum
(
albumName
).
then
((
album
)
=>
{
console
.
info
(
'
createAlbumPromise successfully, album:
'
+
album
.
albumName
+
'
album uri:
'
+
album
.
albumUri
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
createAlbumPromise failed with err:
'
+
err
);
});
}
...
...
@@ -649,14 +651,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
// 示例代码为删除相册名为newAlbumName的相册。
console
.
info
(
'
deleteAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
equalTo
(
'
album_name
'
,
'
newAlbumName
'
);
let
fetchOptions
=
{
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
fetchOptions
);
let
album
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
fetchOptions
);
let
album
:
photoAccessHelper
.
Album
=
await
fetchResult
.
getFirstObject
();
phAccessHelper
.
deleteAlbums
([
album
],
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
deletePhotoAlbumsCallback failed with err:
'
+
err
);
...
...
@@ -707,21 +709,22 @@ deleteAlbums(albums: Array<Album>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
// 示例代码为删除相册名为newAlbumName的相册。
console
.
info
(
'
deleteAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
equalTo
(
'
album_name
'
,
'
newAlbumName
'
);
let
fetchOptions
=
{
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
fetchOptions
);
let
album
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
fetchOptions
);
let
album
:
photoAccessHelper
.
Album
=
await
fetchResult
.
getFirstObject
();
phAccessHelper
.
deleteAlbums
([
album
]).
then
(()
=>
{
console
.
info
(
'
deletePhotoAlbumsPromise successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
deletePhotoAlbumsPromise failed with err:
'
+
err
);
});
fetchResult
.
close
();
...
...
@@ -765,9 +768,9 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
// 示例代码中为获取相册名为newAlbumName的相册。
console
.
info
(
'
getAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
equalTo
(
'
album_name
'
,
'
newAlbumName
'
);
let
fetchOptions
=
{
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
...
...
@@ -830,7 +833,7 @@ async function example() {
console
.
error
(
'
getAlbumsCallback fetchResult is undefined
'
);
return
;
}
let
album
=
await
fetchResult
.
getFirstObject
();
let
album
:
photoAccessHelper
.
Album
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getAlbumsCallback successfully, albumUri:
'
+
album
.
albumUri
);
fetchResult
.
close
();
});
...
...
@@ -875,13 +878,14 @@ getAlbums(type: AlbumType, subtype: AlbumSubtype, options?: FetchOptions): Promi
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
// 示例代码中为获取相册名为newAlbumName的相册。
console
.
info
(
'
getAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
equalTo
(
'
album_name
'
,
'
newAlbumName
'
);
let
fetchOptions
=
{
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
...
...
@@ -890,10 +894,10 @@ async function example() {
console
.
error
(
'
getAlbumsPromise fetchResult is undefined
'
);
return
;
}
let
album
=
await
fetchResult
.
getFirstObject
();
let
album
:
photoAccessHelper
.
Album
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getAlbumsPromise successfully, albumName:
'
+
album
.
albumName
);
fetchResult
.
close
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
getAlbumsPromise failed with err:
'
+
err
);
});
}
...
...
@@ -934,29 +938,28 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
deleteAssetDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
const
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
var
asset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
phAccessHelper
.
deleteAssets
([
asset
.
uri
],
(
err
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
'
deleteAssets successfully
'
);
}
else
{
console
.
error
(
'
deleteAssets failed with error:
'
+
err
);
}
});
}
catch
(
err
)
{
console
.
info
(
'
fetch failed, message =
'
,
err
);
}
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
phAccessHelper
.
deleteAssets
([
asset
.
uri
],
(
err
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
'
deleteAssets successfully
'
);
}
else
{
console
.
error
(
'
deleteAssets failed with error:
'
+
err
);
}
});
}
```
...
...
@@ -1000,23 +1003,18 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
deleteDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
const
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
var
asset
=
await
fetchResult
.
getFirstObject
();
}
catch
(
err
)
{
console
.
info
(
'
fetch failed, message =
'
,
err
);
}
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
try
{
const
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
await
phAccessHelper
.
deleteAssets
([
asset
.
uri
]);
console
.
info
(
'
deleteAssets successfully
'
);
}
catch
(
err
)
{
...
...
@@ -1058,21 +1056,21 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
registerChangeDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
if
(
photoAsset
!=
undefined
)
{
console
.
info
(
'
photoAsset.displayName :
'
+
photoAsset
.
displayName
);
}
let
onCallback1
=
(
changeData
)
=>
{
let
onCallback1
=
(
changeData
:
photoAccessHelper
.
ChangeData
)
=>
{
console
.
info
(
'
onCallback1 success, changData:
'
+
JSON
.
stringify
(
changeData
));
//file had changed, do something
}
let
onCallback2
=
(
changeData
)
=>
{
let
onCallback2
=
(
changeData
:
photoAccessHelper
.
ChangeData
)
=>
{
console
.
info
(
'
onCallback2 success, changData:
'
+
JSON
.
stringify
(
changeData
));
//file had changed, do something
}
...
...
@@ -1123,20 +1121,20 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
offDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
if
(
photoAsset
!=
undefined
)
{
console
.
info
(
'
photoAsset.displayName :
'
+
photoAsset
.
displayName
);
}
let
onCallback1
=
(
changeData
)
=>
{
let
onCallback1
=
(
changeData
:
photoAccessHelper
.
ChangeData
)
=>
{
console
.
info
(
'
onCallback1 on
'
);
}
let
onCallback2
=
(
changeData
)
=>
{
let
onCallback2
=
(
changeData
:
photoAccessHelper
.
ChangeData
)
=>
{
console
.
info
(
'
onCallback2 on
'
);
}
// 注册onCallback1监听
...
...
@@ -1187,29 +1185,28 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
createDeleteRequestDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
const
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
var
asset
=
await
fetchResult
.
getFirstObject
();
const
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
phAccessHelper
.
createDeleteRequest
([
asset
.
uri
],
(
err
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
'
createDeleteRequest successfully
'
);
}
else
{
console
.
error
(
'
createDeleteRequest failed with error:
'
+
err
);
}
});
}
catch
(
err
)
{
console
.
info
(
'
fetch failed, message =
'
,
err
);
}
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
phAccessHelper
.
createDeleteRequest
([
asset
.
uri
],
(
err
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
'
createDeleteRequest successfully
'
);
}
else
{
console
.
error
(
'
createDeleteRequest failed with error:
'
+
err
);
}
});
}
```
...
...
@@ -1250,23 +1247,18 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
createDeleteRequestDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
const
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
var
asset
=
await
fetchResult
.
getFirstObject
();
}
catch
(
err
)
{
console
.
info
(
'
fetch failed, message =
'
,
err
);
}
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
try
{
const
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
await
phAccessHelper
.
createDeleteRequest
([
asset
.
uri
]);
console
.
info
(
'
createDeleteRequest successfully
'
);
}
catch
(
err
)
{
...
...
@@ -1317,24 +1309,24 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
getPhotoIndexDemo
'
);
let
predicatesForGetAsset
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOp
=
{
let
predicatesForGetAsset
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOp
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicatesForGetAsset
};
// Obtain the uri of the album
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
FAVORITE
,
fetchOp
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
FAVORITE
,
fetchOp
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
orderByAsc
(
photoAccessHelper
.
PhotoKeys
.
DATE_MODIFIED
);
let
fetchOptions
=
{
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[
photoAccessHelper
.
PhotoKeys
.
DATE_MODIFIED
],
predicates
:
predicates
};
let
photoFetchResult
=
await
album
.
getAssets
(
fetchOptions
);
let
photoFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOptions
);
let
expectIndex
=
1
;
// Obtain the uri of the second file
let
photoAsset
=
await
photoFetchResult
.
getObjectByPosition
(
expectIndex
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
photoFetchResult
.
getObjectByPosition
(
expectIndex
);
phAccessHelper
.
getPhotoIndex
(
photoAsset
.
uri
,
album
.
albumUri
,
fetchOptions
,
(
err
,
index
)
=>
{
if
(
err
==
undefined
)
{
...
...
@@ -1387,31 +1379,32 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promis
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
getPhotoIndexDemo
'
);
let
predicatesForGetAsset
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOp
=
{
let
predicatesForGetAsset
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOp
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicatesForGetAsset
};
// Obtain the uri of the album
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
FAVORITE
,
fetchOp
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
FAVORITE
,
fetchOp
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
orderByAsc
(
photoAccessHelper
.
PhotoKeys
.
DATE_MODIFIED
);
let
fetchOptions
=
{
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[
photoAccessHelper
.
PhotoKeys
.
DATE_MODIFIED
],
predicates
:
predicates
};
let
photoFetchResult
=
await
album
.
getAssets
(
fetchOptions
);
let
photoFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOptions
);
let
expectIndex
=
1
;
// Obtain the uri of the second file
let
photoAsset
=
await
photoFetchResult
.
getObjectByPosition
(
expectIndex
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
photoFetchResult
.
getObjectByPosition
(
expectIndex
);
phAccessHelper
.
getPhotoIndex
(
photoAsset
.
uri
,
album
.
albumUri
,
fetchOptions
).
then
((
index
)
=>
{
console
.
info
(
`getPhotoIndex successfully and index is :
${
index
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
`getPhotoIndex failed; error:
${
err
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1545,15 +1538,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
photoAssetGetDemo
'
);
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[
'
title
'
],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
title
=
photoAccessHelper
.
PhotoKeys
.
TITLE
;
let
photoAssetTitle
=
photoAsset
.
get
(
title
.
toString
());
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
title
:
photoAccessHelper
.
PhotoKeys
=
photoAccessHelper
.
PhotoKeys
.
TITLE
;
let
photoAssetTitle
:
photoAccessHelper
.
MemberType
=
photoAsset
.
get
(
title
.
toString
());
console
.
info
(
'
photoAsset Get photoAssetTitle =
'
,
photoAssetTitle
);
}
catch
(
err
)
{
console
.
error
(
'
release failed. message =
'
,
err
);
...
...
@@ -1592,14 +1585,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
photoAssetSetDemo
'
);
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[
'
title
'
],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
title
=
photoAccessHelper
.
PhotoKeys
.
TITLE
.
toString
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
title
:
string
=
photoAccessHelper
.
PhotoKeys
.
TITLE
.
toString
();
photoAsset
.
set
(
title
,
'
newTitle
'
);
}
catch
(
err
)
{
console
.
error
(
'
release failed. message =
'
,
err
);
...
...
@@ -1638,20 +1631,20 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
commitModifyDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[
'
title
'
],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
title
=
photoAccessHelper
.
PhotoKeys
.
TITLE
.
toString
();
let
photoAssetTitle
=
photoAsset
.
get
(
title
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
title
:
string
=
photoAccessHelper
.
PhotoKeys
.
TITLE
.
toString
();
let
photoAssetTitle
:
photoAccessHelper
.
MemberType
=
photoAsset
.
get
(
title
);
console
.
info
(
'
photoAsset get photoAssetTitle =
'
,
photoAssetTitle
);
photoAsset
.
set
(
title
,
'
newTitle2
'
);
photoAsset
.
commitModify
((
err
)
=>
{
if
(
err
==
undefined
)
{
let
newPhotoAssetTitle
=
photoAsset
.
get
(
title
);
let
newPhotoAssetTitle
:
photoAccessHelper
.
MemberType
=
photoAsset
.
get
(
title
);
console
.
info
(
'
photoAsset get newPhotoAssetTitle =
'
,
newPhotoAssetTitle
);
}
else
{
console
.
error
(
'
commitModify failed, message =
'
,
err
);
...
...
@@ -1691,20 +1684,20 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
commitModifyDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[
'
title
'
],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
title
=
photoAccessHelper
.
PhotoKeys
.
TITLE
.
toString
();
let
photoAssetTitle
=
photoAsset
.
get
(
title
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
title
:
string
=
photoAccessHelper
.
PhotoKeys
.
TITLE
.
toString
();
let
photoAssetTitle
:
photoAccessHelper
.
MemberType
=
photoAsset
.
get
(
title
);
console
.
info
(
'
photoAsset get photoAssetTitle =
'
,
photoAssetTitle
);
photoAsset
.
set
(
title
,
'
newTitle3
'
);
try
{
await
photoAsset
.
commitModify
();
let
newPhotoAssetTitle
=
photoAsset
.
get
(
title
);
let
newPhotoAssetTitle
:
photoAccessHelper
.
MemberType
=
photoAsset
.
get
(
title
);
console
.
info
(
'
photoAsset get newPhotoAssetTitle =
'
,
newPhotoAssetTitle
);
}
catch
(
err
)
{
console
.
error
(
'
release failed. message =
'
,
err
);
...
...
@@ -1747,8 +1740,8 @@ open(mode: string, callback: AsyncCallback<number>): void
```
ts
async
function
example
()
{
console
.
info
(
'
openDemo
'
);
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
photoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
photoAsset
.
open
(
'
rw
'
,
(
err
,
fd
)
=>
{
if
(
fd
!=
undefined
)
{
console
.
info
(
'
File fd
'
+
fd
);
...
...
@@ -1801,9 +1794,9 @@ open(mode: string): Promise<number>
async
function
example
()
{
console
.
info
(
'
openDemo
'
);
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
photoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
let
fd
=
await
photoAsset
.
open
(
'
rw
'
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
let
fd
:
number
=
await
photoAsset
.
open
(
'
rw
'
);
if
(
fd
!=
undefined
)
{
console
.
info
(
'
File fd
'
+
fd
);
photoAsset
.
close
(
fd
);
...
...
@@ -1847,8 +1840,8 @@ getReadOnlyFd(callback: AsyncCallback<number>): void
```
ts
async
function
example
()
{
console
.
info
(
'
getReadOnlyFdDemo
'
);
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
photoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
photoAsset
.
getReadOnlyFd
((
err
,
fd
)
=>
{
if
(
fd
!=
undefined
)
{
console
.
info
(
'
File fd
'
+
fd
);
...
...
@@ -1892,9 +1885,9 @@ getReadOnlyFd(): Promise<number>
async
function
example
()
{
console
.
info
(
'
getReadOnlyFdDemo
'
);
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
photoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
let
fd
=
await
photoAsset
.
getReadOnlyFd
();
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
phAccessHelper
.
createAsset
(
testFileName
);
let
fd
:
number
=
await
photoAsset
.
getReadOnlyFd
();
if
(
fd
!=
undefined
)
{
console
.
info
(
'
File fd
'
+
fd
);
photoAsset
.
close
(
fd
);
...
...
@@ -1938,14 +1931,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
closeDemo
'
);
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
fd
=
await
photoAsset
.
open
(
'
rw
'
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
fd
:
number
=
await
photoAsset
.
open
(
'
rw
'
);
console
.
info
(
'
file fd
'
,
fd
);
photoAsset
.
close
(
fd
,
(
err
)
=>
{
if
(
err
==
undefined
)
{
...
...
@@ -1996,13 +1989,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
closeDemo
'
);
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
fd
=
await
asset
.
open
(
'
rw
'
);
console
.
info
(
'
file fd
'
,
fd
);
await
asset
.
close
(
fd
);
...
...
@@ -2044,13 +2037,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getThumbnailDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
asset displayName =
'
,
asset
.
displayName
);
asset
.
getThumbnail
((
err
,
pixelMap
)
=>
{
if
(
err
==
undefined
)
{
...
...
@@ -2091,16 +2084,17 @@ getThumbnail(size: image.Size, callback: AsyncCallback<image.PixelMap>): v
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
image
from
'
@ohos.multimedia.image
'
async
function
example
()
{
console
.
info
(
'
getThumbnailDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
size
=
{
width
:
720
,
height
:
720
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
size
:
image
.
Size
=
{
width
:
720
,
height
:
720
};
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
asset displayName =
'
,
asset
.
displayName
);
asset
.
getThumbnail
(
size
,
(
err
,
pixelMap
)
=>
{
...
...
@@ -2147,21 +2141,23 @@ getThumbnail(size?: image.Size): Promise<image.PixelMap>
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
image
from
'
@ohos.multimedia.image
'
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
getThumbnailDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
size
=
{
width
:
720
,
height
:
720
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
size
:
image
.
Size
=
{
width
:
720
,
height
:
720
};
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
asset displayName =
'
,
asset
.
displayName
);
asset
.
getThumbnail
(
size
).
then
((
pixelMap
)
=>
{
console
.
info
(
'
getThumbnail successful
'
+
pixelMap
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
getThumbnail fail
'
+
err
);
});
}
...
...
@@ -2202,12 +2198,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
setFavoriteDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
asset
.
setFavorite
(
true
,
(
err
)
=>
{
if
(
err
==
undefined
)
{
...
...
@@ -2256,19 +2252,20 @@ setFavorite(favoriteState: boolean): Promise<void>
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
setFavoriteDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
asset
.
setFavorite
(
true
).
then
(
function
()
{
asset
.
setFavorite
(
true
).
then
(
()
=>
{
console
.
info
(
'
setFavorite successfully
'
);
}).
catch
(
function
(
err
)
{
}).
catch
(
(
err
:
BusinessError
)
=>
{
console
.
error
(
'
setFavorite failed with error:
'
+
err
);
});
}
...
...
@@ -2311,12 +2308,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
setHiddenDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
asset
.
setHidden
(
true
,
(
err
)
=>
{
if
(
err
==
undefined
)
{
...
...
@@ -2367,22 +2364,23 @@ setHidden(hiddenState: boolean): Promise<void>
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
// 示例代码为将文件从隐藏相册中恢复,需要先在隐藏相册预置资源
console
.
info
(
'
setHiddenDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumList
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
HIDDEN
);
let
albumList
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
HIDDEN
);
const
album
=
await
albumList
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
asset
.
setHidden
(
false
).
then
(()
=>
{
console
.
info
(
'
setHidden successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
setHidden failed with error:
'
+
err
);
});
}
...
...
@@ -2458,19 +2456,16 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
getExifDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
isNotNull
(
'
all_exif
'
)
let
fetchOptions
=
{
fetchColumns
:
[
'
all_exif
'
,
photoAccessHelper
.
PhotoKeys
.
USER_COMMENT
],
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[
'
all_exif
'
,
photoAccessHelper
.
PhotoKeys
.
USER_COMMENT
],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getExifDemo fileAsset displayName:
'
+
JSON
.
stringify
(
fileAsset
.
displayName
));
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fileAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
exifMessage
=
await
fileAsset
.
getExif
();
let
userCommentKey
=
'
UserComment
'
;
let
userComment
=
JSON
.
stringify
(
JSON
.
parse
(
exifMessage
),
[
userCommentKey
]);
console
.
info
(
'
getExifDemo userComment:
'
+
JSON
.
stringify
(
userComment
));
fetchResult
.
close
();
}
catch
(
err
)
{
console
.
error
(
'
getExifDemoCallback failed with error:
'
+
err
);
...
...
@@ -2548,14 +2543,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
getExifDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
isNotNull
(
'
all_exif
'
)
let
fetchOptions
=
{
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[
'
all_exif
'
,
photoAccessHelper
.
PhotoKeys
.
USER_COMMENT
],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fileAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getExifDemo fileAsset displayName:
'
+
JSON
.
stringify
(
fileAsset
.
displayName
));
let
userCommentKey
=
'
UserComment
'
;
fileAsset
.
getExif
((
err
,
exifMessage
)
=>
{
...
...
@@ -2607,13 +2602,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
setUserCommentDemo
'
)
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fileAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
userComment
=
'
test_set_user_comment
'
;
await
fileAsset
.
setUserComment
(
userComment
);
}
catch
(
err
)
{
...
...
@@ -2651,13 +2646,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
setUserCommentDemo
'
)
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOptions
);
let
fileAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
let
userComment
=
'
test_set_user_comment
'
;
fileAsset
.
setUserComment
(
userComment
,
(
err
)
=>
{
if
(
err
===
undefined
)
{
...
...
@@ -2705,12 +2700,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getCountDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
fetchCount
=
fetchResult
.
getCount
();
console
.
info
(
'
fetchCount =
'
,
fetchCount
);
}
...
...
@@ -2744,15 +2739,15 @@ isAfterLast(): boolean
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
async
function
example
()
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
const
fetchCount
=
fetchResult
.
getCount
();
console
.
info
(
'
count:
'
+
fetchCount
);
let
photoAsset
=
await
fetchResult
.
getLastObject
();
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getLastObject
();
if
(
fetchResult
.
isAfterLast
())
{
console
.
info
(
'
photoAsset isAfterLast displayName =
'
,
photoAsset
.
displayName
);
}
else
{
...
...
@@ -2784,13 +2779,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
fetchResultCloseDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
fetchResult
.
close
();
console
.
info
(
'
close succeed.
'
);
}
catch
(
err
)
{
...
...
@@ -2828,12 +2823,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getFirstObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
fetchResult
.
getFirstObject
((
err
,
photoAsset
)
=>
{
if
(
photoAsset
!=
undefined
)
{
console
.
info
(
'
photoAsset displayName:
'
,
photoAsset
.
displayName
);
...
...
@@ -2873,13 +2868,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getFirstObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
photoAsset displayName:
'
,
photoAsset
.
displayName
);
}
```
...
...
@@ -2913,12 +2908,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getNextObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
await
fetchResult
.
getFirstObject
();
if
(
fetchResult
.
isAfterLast
())
{
fetchResult
.
getNextObject
((
err
,
photoAsset
)
=>
{
...
...
@@ -2961,15 +2956,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getNextObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
await
fetchResult
.
getFirstObject
();
if
(
fetchResult
.
isAfterLast
())
{
let
photoAsset
=
await
fetchResult
.
getNextObject
();
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getNextObject
();
console
.
info
(
'
photoAsset displayName:
'
,
photoAsset
.
displayName
);
}
}
...
...
@@ -3004,12 +2999,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getLastObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
fetchResult
.
getLastObject
((
err
,
photoAsset
)
=>
{
if
(
photoAsset
!=
undefined
)
{
console
.
info
(
'
photoAsset displayName:
'
,
photoAsset
.
displayName
);
...
...
@@ -3049,13 +3044,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getLastObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
=
await
fetchResult
.
getLastObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getLastObject
();
console
.
info
(
'
photoAsset displayName:
'
,
photoAsset
.
displayName
);
}
```
...
...
@@ -3090,12 +3085,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getObjectByPositionDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
fetchResult
.
getObjectByPosition
(
0
,
(
err
,
photoAsset
)
=>
{
if
(
photoAsset
!=
undefined
)
{
console
.
info
(
'
photoAsset displayName:
'
,
photoAsset
.
displayName
);
...
...
@@ -3141,13 +3136,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getObjectByPositionDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
=
await
fetchResult
.
getObjectByPosition
(
0
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAsset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getObjectByPosition
(
0
);
console
.
info
(
'
photoAsset displayName:
'
,
photoAsset
.
displayName
);
}
```
...
...
@@ -3181,12 +3176,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getAllObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
fetchResult
.
getAllObjects
((
err
,
photoAssetList
)
=>
{
if
(
photoAssetList
!=
undefined
)
{
console
.
info
(
'
photoAssetList length:
'
,
photoAssetList
.
length
);
...
...
@@ -3226,13 +3221,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getAllObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAssetList
=
await
fetchResult
.
getAllObjects
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
photoAssetList
:
Array
<
photoAccessHelper
.
PhotoAsset
>
=
await
fetchResult
.
getAllObjects
();
console
.
info
(
'
photoAssetList length:
'
,
photoAssetList
.
length
);
}
```
...
...
@@ -3286,17 +3281,17 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
albumGetAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchOption
=
{
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
albumList
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
albumFetchOptions
);
const
album
=
await
albumList
.
getFirstObject
();
const
albumList
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
albumFetchOptions
);
const
album
:
photoAccessHelper
.
Album
=
await
albumList
.
getFirstObject
();
album
.
getAssets
(
fetchOption
,
(
err
,
albumFetchResult
)
=>
{
if
(
albumFetchResult
!=
undefined
)
{
console
.
info
(
'
album getAssets successfully, getCount:
'
+
albumFetchResult
.
getCount
());
...
...
@@ -3341,24 +3336,25 @@ getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
albumGetAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchOption
=
{
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
albumList
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
albumFetchOptions
);
const
album
=
await
albumList
.
getFirstObject
();
const
albumList
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
albumFetchOptions
);
const
album
:
photoAccessHelper
.
Album
=
await
albumList
.
getFirstObject
();
album
.
getAssets
(
fetchOption
).
then
((
albumFetchResult
)
=>
{
console
.
info
(
'
album getPhotoAssets successfully, getCount:
'
+
albumFetchResult
.
getCount
());
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album getPhotoAssets failed with error:
'
+
err
);
});
}
...
...
@@ -3395,13 +3391,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
albumCommitModifyDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
albumList
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
albumFetchOptions
);
const
album
=
await
albumList
.
getFirstObject
();
const
albumList
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
albumFetchOptions
);
const
album
:
photoAccessHelper
.
Album
=
await
albumList
.
getFirstObject
();
album
.
albumName
=
'
hello
'
;
album
.
commitModify
((
err
)
=>
{
if
(
err
!=
undefined
)
{
...
...
@@ -3441,20 +3437,21 @@ commitModify(): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
albumCommitModifyDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
albumList
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
albumFetchOptions
);
const
album
=
await
albumList
.
getFirstObject
();
const
albumList
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
,
albumFetchOptions
);
const
album
:
photoAccessHelper
.
Album
=
await
albumList
.
getFirstObject
();
album
.
albumName
=
'
hello
'
;
album
.
commitModify
().
then
(()
=>
{
console
.
info
(
'
commitModify successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
commitModify failed with error:
'
+
err
);
});
}
...
...
@@ -3493,15 +3490,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
addAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
addAssets
([
asset
],
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album addAssets successfully
'
);
...
...
@@ -3549,22 +3546,23 @@ addAssets(assets: Array<PhotoAsset>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
addAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
phAccessHelper
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
addAssets
([
asset
]).
then
(()
=>
{
console
.
info
(
'
album addAssets successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album addAssets failed with error:
'
+
err
);
});
}
catch
(
err
)
{
...
...
@@ -3606,15 +3604,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
removeAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
removeAssets
([
asset
],
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album removeAssets successfully
'
);
...
...
@@ -3662,22 +3660,23 @@ removeAssets(assets: Array<PhotoAsset>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
removeAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
removeAssets
([
asset
]).
then
(()
=>
{
console
.
info
(
'
album removeAssets successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album removeAssets failed with error:
'
+
err
);
});
}
catch
(
err
)
{
...
...
@@ -3722,15 +3721,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
recoverAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
TRASH
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
TRASH
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
recoverAssets
([
asset
],
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album recoverAssets successfully
'
);
...
...
@@ -3781,22 +3780,23 @@ recoverAssets(assets: Array<PhotoAsset>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
recoverAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
TRASH
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
TRASH
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
recoverAssets
([
asset
]).
then
(()
=>
{
console
.
info
(
'
album recoverAssets successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album recoverAssets failed with error:
'
+
err
);
});
}
catch
(
err
)
{
...
...
@@ -3843,15 +3843,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
deleteAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
TRASH
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
TRASH
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
deleteAssets
([
asset
],
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album deleteAssets successfully
'
);
...
...
@@ -3904,22 +3904,23 @@ deleteAssets(assets: Array<PhotoAsset>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
deleteAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
TRASH
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
SYSTEM
,
photoAccessHelper
.
AlbumSubtype
.
TRASH
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
deleteAssets
([
asset
]).
then
(()
=>
{
console
.
info
(
'
album deleteAssets successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album deleteAssets failed with error:
'
+
err
);
});
}
catch
(
err
)
{
...
...
@@ -3966,15 +3967,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
setCoverUriDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
setCoverUri
(
asset
.
uri
,
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album setCoverUri successfully
'
);
...
...
@@ -4031,15 +4032,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
setCoverUriDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
photoAccessHelper
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
Album
>
=
await
phAccessHelper
.
getAlbums
(
photoAccessHelper
.
AlbumType
.
USER
,
photoAccessHelper
.
AlbumSubtype
.
USER_GENERIC
);
let
album
:
photoAccessHelper
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
photoAccessHelper
.
FetchResult
<
photoAccessHelper
.
PhotoAsset
>
=
await
album
.
getAssets
(
fetchOption
);
let
asset
:
photoAccessHelper
.
PhotoAsset
=
await
fetchResult
.
getFirstObject
();
album
.
setCoverUri
(
asset
.
uri
,
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album setCoverUri successfully
'
);
...
...
zh-cn/application-dev/reference/apis/js-apis-userFileManager.md
浏览文件 @
61090577
...
...
@@ -77,8 +77,8 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getPhotoAssets
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
...
...
@@ -86,7 +86,7 @@ async function example() {
mgr
.
getPhotoAssets
(
fetchOptions
,
async
(
err
,
fetchResult
)
=>
{
if
(
fetchResult
!=
undefined
)
{
console
.
info
(
'
fetchResult success
'
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}
...
...
@@ -134,16 +134,16 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getPhotoAssets
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
if
(
fetchResult
!=
undefined
)
{
console
.
info
(
'
fetchResult success
'
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}
...
...
@@ -187,13 +187,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
createPhotoAssetDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
AlbumFetchOptions
=
{
predicates
:
predicates
};
let
albums
=
await
mgr
.
getPhotoAlbums
(
fetchOptions
);
let
album
=
await
albums
.
getFirstObject
();
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
albums
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getPhotoAlbums
(
fetchOptions
);
let
album
:
userFileManager
.
Album
=
await
albums
.
getFirstObject
();
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
mgr
.
createPhotoAsset
(
testFileName
,
album
.
albumUri
,
(
err
,
fileAsset
)
=>
{
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
createPhotoAsset file displayName
'
+
fileAsset
.
displayName
);
...
...
@@ -236,7 +236,7 @@ createPhotoAsset(displayName: string, callback: AsyncCallback<FileAsset>):
```
ts
async
function
example
()
{
console
.
info
(
'
createPhotoAssetDemo
'
);
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
mgr
.
createPhotoAsset
(
testFileName
,
(
err
,
fileAsset
)
=>
{
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
createPhotoAsset file displayName
'
+
fileAsset
.
displayName
);
...
...
@@ -285,8 +285,8 @@ createPhotoAsset(displayName: string, albumUri?: string): Promise<FileAsset&g
async
function
example
()
{
console
.
info
(
'
createPhotoAssetDemo
'
);
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
fileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
fileAsset
:
userFileManager
.
FileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
console
.
info
(
'
createPhotoAsset file displayName
'
+
fileAsset
.
displayName
);
console
.
info
(
'
createPhotoAsset successfully
'
);
}
catch
(
err
)
{
...
...
@@ -327,8 +327,8 @@ createPhotoAsset(displayName: string, createOption: PhotoCreateOptions, callback
```
ts
async
function
example
()
{
console
.
info
(
'
createPhotoAssetDemo
'
);
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
createOption
=
{
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
createOption
:
userFileManager
.
PhotoCreateOptions
=
{
subType
:
userFileManager
.
PhotoSubType
.
DEFAULT
}
mgr
.
createPhotoAsset
(
testFileName
,
createOption
,
(
err
,
fileAsset
)
=>
{
...
...
@@ -379,11 +379,11 @@ createPhotoAsset(displayName: string, createOption: PhotoCreateOptions): Promise
async
function
example
()
{
console
.
info
(
'
createPhotoAssetDemo
'
);
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
createOption
=
{
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
createOption
:
userFileManager
.
PhotoCreateOptions
=
{
subType
:
userFileManager
.
PhotoSubType
.
DEFAULT
}
let
fileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
,
createOption
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
,
createOption
);
console
.
info
(
'
createPhotoAsset file displayName
'
+
fileAsset
.
displayName
);
console
.
info
(
'
createPhotoAsset successfully
'
);
}
catch
(
err
)
{
...
...
@@ -423,7 +423,7 @@ createAudioAsset(displayName: string, callback: AsyncCallback<FileAsset>):
```
ts
async
function
example
()
{
console
.
info
(
'
createAudioAssetDemo
'
);
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.mp3
'
;
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.mp3
'
;
mgr
.
createAudioAsset
(
testFileName
,
(
err
,
fileAsset
)
=>
{
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
createAudioAsset file displayName
'
+
fileAsset
.
displayName
);
...
...
@@ -471,8 +471,8 @@ createAudioAsset(displayName: string): Promise<FileAsset>;
async
function
example
()
{
console
.
info
(
'
createAudioAssetDemo
'
);
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.mp3
'
;
let
fileAsset
=
await
mgr
.
createAudioAsset
(
testFileName
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.mp3
'
;
let
fileAsset
:
userFileManager
.
FileAsset
=
await
mgr
.
createAudioAsset
(
testFileName
);
console
.
info
(
'
createAudioAsset file displayName
'
+
fileAsset
.
displayName
);
console
.
info
(
'
createAudioAsset successfully
'
);
}
catch
(
err
)
{
...
...
@@ -509,7 +509,7 @@ createAlbum(name: string, callback: AsyncCallback<Album>): void;
```ts
async function example() {
console.info('createAlbumDemo');
let albumName = 'newAlbumName' + new Date().getTime();
let albumName
: string
= 'newAlbumName' + new Date().getTime();
mgr.createAlbum(albumName, (err, album) => {
if (err) {
console.error('createAlbumCallback failed with err: ' + err);
...
...
@@ -551,12 +551,14 @@ createAlbum(name: string): Promise<Album>;
**示例:**
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
createAlbumDemo
'
);
let
albumName
=
'
newAlbumName
'
+
new
Date
().
getTime
();
let
albumName
:
string
=
'
newAlbumName
'
+
new
Date
().
getTime
();
mgr
.
createAlbum
(
albumName
).
then
((
album
)
=>
{
console
.
info
(
'
createAlbumPromise successfully, album:
'
+
album
.
albumName
+
'
album uri:
'
+
album
.
albumUri
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
createAlbumPromise failed with err:
'
+
err
);
});
}
...
...
@@ -589,14 +591,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
// 示例代码为删除相册名为newAlbumName的相册。
console
.
info
(
'
deleteAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
equalTo
(
'
album_name
'
,
'
newAlbumName
'
);
let
fetchOptions
=
{
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
,
fetchOptions
);
let
album
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
,
fetchOptions
);
let
album
:
userFileManager
.
Album
=
await
fetchResult
.
getFirstObject
();
mgr
.
deleteAlbums
([
album
],
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
deletePhotoAlbumsCallback failed with err:
'
+
err
);
...
...
@@ -636,21 +638,22 @@ deleteAlbums(albums: Array<Album>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
// 示例代码为删除相册名为newAlbumName的相册。
console
.
info
(
'
deleteAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
equalTo
(
'
album_name
'
,
'
newAlbumName
'
);
let
fetchOptions
=
{
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
,
fetchOptions
);
let
album
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
,
fetchOptions
);
let
album
:
userFileManager
.
Album
=
await
fetchResult
.
getFirstObject
();
mgr
.
deleteAlbums
([
album
]).
then
(()
=>
{
console
.
info
(
'
deletePhotoAlbumsPromise successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
deletePhotoAlbumsPromise failed with err:
'
+
err
);
});
fetchResult
.
close
();
...
...
@@ -694,9 +697,9 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
// 示例代码中为获取相册名为newAlbumName的相册。
console
.
info
(
'
getAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
equalTo
(
'
album_name
'
,
'
newAlbumName
'
);
let
fetchOptions
=
{
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
...
...
@@ -709,7 +712,7 @@ async function example() {
console
.
error
(
'
getAlbumsCallback fetchResult is undefined
'
);
return
;
}
let
album
=
await
fetchResult
.
getFirstObject
();
let
album
:
userFileManager
.
Album
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getAlbumsCallback successfully, albumName:
'
+
album
.
albumName
);
fetchResult
.
close
();
});
...
...
@@ -759,7 +762,7 @@ async function example() {
console
.
error
(
'
getAlbumsCallback fetchResult is undefined
'
);
return
;
}
let
album
=
await
fetchResult
.
getFirstObject
();
let
album
:
userFileManager
.
Album
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getAlbumsCallback successfully, albumUri:
'
+
album
.
albumUri
);
fetchResult
.
close
();
});
...
...
@@ -804,13 +807,14 @@ getAlbums(type: AlbumType, subType: AlbumSubType, options?: FetchOptions): Promi
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
// 示例代码中为获取相册名为newAlbumName的相册。
console
.
info
(
'
getAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
equalTo
(
'
album_name
'
,
'
newAlbumName
'
);
let
fetchOptions
=
{
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
...
...
@@ -819,10 +823,10 @@ async function example() {
console
.
error
(
'
getAlbumsPromise fetchResult is undefined
'
);
return
;
}
let
album
=
await
fetchResult
.
getFirstObject
();
let
album
:
userFileManager
.
Album
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getAlbumsPromise successfully, albumName:
'
+
album
.
albumName
);
fetchResult
.
close
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
getAlbumsPromise failed with err:
'
+
err
);
});
}
...
...
@@ -862,8 +866,8 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getPhotoAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
userFileManager
.
AlbumFetchOptions
=
{
predicates
:
predicates
};
...
...
@@ -923,14 +927,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getPhotoAlbumsDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
userFileManager
.
AlbumFetchOptions
=
{
predicates
:
predicates
};
try
{
let
fetchResult
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
console
.
info
(
'
album.count =
'
+
fetchResult
.
getCount
());
const
album
=
await
fetchResult
.
getFirstObject
();
const
album
:
userFileManager
.
Album
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
first album.albumName =
'
+
album
.
albumName
);
}
catch
(
err
)
{
console
.
error
(
'
getPhotoAlbums fail, message =
'
+
err
);
...
...
@@ -972,7 +976,7 @@ async function example() {
console
.
info
(
'
getPrivateAlbumDemo
'
);
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
,
async
(
err
,
fetchResult
)
=>
{
if
(
fetchResult
!=
undefined
)
{
let
trashAlbum
=
await
fetchResult
.
getFirstObject
();
let
trashAlbum
:
userFileManager
.
PrivateAlbum
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
first album.albumName =
'
+
trashAlbum
.
albumName
);
}
else
{
console
.
error
(
'
getPrivateAlbum failed. message =
'
,
err
);
...
...
@@ -1019,8 +1023,8 @@ getPrivateAlbum(type: PrivateAlbumType): Promise<FetchResult<PrivateAlbum&
async
function
example
()
{
console
.
info
(
'
getPrivateAlbumDemo
'
);
try
{
let
fetchResult
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
trashAlbum
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
PrivateAlbum
>
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
trashAlbum
:
userFileManager
.
PrivateAlbum
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
first album.albumName =
'
+
trashAlbum
.
albumName
);
}
catch
(
err
)
{
console
.
error
(
'
getPrivateAlbum failed. message =
'
,
err
);
...
...
@@ -1060,8 +1064,8 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getAudioAssets
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
...
...
@@ -1069,7 +1073,7 @@ async function example() {
mgr
.
getAudioAssets
(
fetchOptions
,
async
(
err
,
fetchResult
)
=>
{
if
(
fetchResult
!=
undefined
)
{
console
.
info
(
'
fetchFileResult success
'
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}
...
...
@@ -1118,24 +1122,23 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getAudioAssets
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
var
fetchResult
=
await
mgr
.
getAudioAssets
(
fetchOptions
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getAudioAssets
(
fetchOptions
);
if
(
fetchResult
!=
undefined
)
{
console
.
info
(
'
fetchFileResult success
'
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}
}
}
catch
(
err
)
{
console
.
error
(
'
getAudioAssets failed, message =
'
,
err
);
}
if
(
fetchResult
!=
undefined
)
{
console
.
info
(
'
fetchFileResult success
'
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}
}
}
```
...
...
@@ -1171,29 +1174,30 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
deleteAssetDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
const
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
var
asset
=
await
fetchResult
.
getFirstObject
();
const
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
mgr
.
delete
(
asset
.
uri
,
(
err
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
'
delete successfully
'
);
}
else
{
console
.
error
(
'
delete failed with error:
'
+
err
);
}
});
}
catch
(
err
)
{
console
.
info
(
'
fetch failed, message =
'
,
err
);
}
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
mgr
.
delete
(
asset
.
uri
,
(
err
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
'
delete successfully
'
);
}
else
{
console
.
error
(
'
delete failed with error:
'
+
err
);
}
});
}
```
...
...
@@ -1234,23 +1238,18 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
deleteDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
const
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
var
asset
=
await
fetchResult
.
getFirstObject
();
}
catch
(
err
)
{
console
.
info
(
'
fetch failed, message =
'
,
err
);
}
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
try
{
const
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
);
return
;
}
await
mgr
.
delete
(
asset
.
uri
);
console
.
info
(
'
delete successfully
'
);
}
catch
(
err
)
{
...
...
@@ -1311,18 +1310,18 @@ getActivePeers(): Promise<Array<PeerInfo>>;
async
function
example
()
{
console
.
info
(
'
getActivePeersDemo
'
);
try
{
var
devicesInfo
=
await
mgr
.
getActivePeers
();
let
devicesInfo
:
Array
<
userFileManager
.
PeerInfo
>
=
await
mgr
.
getActivePeers
();
if
(
devicesInfo
!=
undefined
)
{
console
.
log
(
'
getActivePeers succeed.
'
);
for
(
let
i
=
0
;
i
<
devicesInfo
.
length
;
i
++
)
{
console
.
info
(
'
get distributed info
'
+
devicesInfo
[
i
].
deviceName
+
devicesInfo
[
i
].
networkId
);
}
}
else
{
console
.
error
(
'
get distributed fail
'
);
}
}
catch
(
err
)
{
console
.
error
(
'
getActivePeers failed. message =
'
,
err
);
}
if
(
devicesInfo
!=
undefined
)
{
console
.
log
(
'
getActivePeers succeed.
'
);
for
(
let
i
=
0
;
i
<
devicesInfo
.
length
;
i
++
)
{
console
.
info
(
'
get distributed info
'
+
devicesInfo
[
i
].
deviceName
+
devicesInfo
[
i
].
networkId
);
}
}
else
{
console
.
error
(
'
get distributed fail
'
);
}
}
```
...
...
@@ -1378,18 +1377,19 @@ getAllPeers(): Promise<Array<PeerInfo>>;
async
function
example
()
{
console
.
info
(
'
getAllPeersDemo
'
);
try
{
var
devicesInfo
=
await
mgr
.
getAllPeers
();
let
devicesInfo
:
Array
<
userFileManager
.
PeerInfo
>
=
await
mgr
.
getAllPeers
();
if
(
devicesInfo
!=
undefined
)
{
console
.
log
(
'
getAllPeers succeed.
'
);
for
(
let
i
=
0
;
i
<
devicesInfo
.
length
;
i
++
)
{
console
.
info
(
'
get distributed info
'
+
devicesInfo
[
i
].
deviceName
+
devicesInfo
[
i
].
networkId
);
}
}
else
{
console
.
error
(
'
get distributed fail
'
);
}
}
catch
(
err
)
{
console
.
error
(
'
getAllPeers failed. message =
'
,
err
);
}
if
(
devicesInfo
!=
undefined
)
{
console
.
log
(
'
getAllPeers succeed.
'
);
for
(
let
i
=
0
;
i
<
devicesInfo
.
length
;
i
++
)
{
console
.
info
(
'
get distributed info
'
+
devicesInfo
[
i
].
deviceName
+
devicesInfo
[
i
].
networkId
);
}
}
else
{
console
.
error
(
'
get distributed fail
'
);
}
}
```
...
...
@@ -1435,24 +1435,24 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
getPhotoIndexDemo
'
);
let
predicatesForGetAsset
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOp
=
{
let
predicatesForGetAsset
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOp
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicatesForGetAsset
};
// Obtain the uri of the album
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
FAVORITE
,
fetchOp
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
orderByAsc
(
userFileManager
.
ImageVideoKey
.
DATE_MODIFIED
);
let
fetchOptions
=
{
fetchColumns
:
[
userFileManager
.
ImageVideoKey
.
DATE_MODIFIED
],
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
FAVORITE
,
fetchOp
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
orderByAsc
(
userFileManager
.
ImageVideoKey
.
DATE_MODIFIED
.
toString
()
);
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[
userFileManager
.
ImageVideoKey
.
DATE_MODIFIED
.
toString
()
],
predicates
:
predicates
};
let
photoFetchResult
=
await
album
.
getPhotoAssets
(
fetchOptions
);
let
photoFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOptions
);
let
expectIndex
=
1
;
// Obtain the uri of the second file
let
photoAsset
=
await
photoFetchResult
.
getPositionObject
(
expectIndex
);
let
photoAsset
:
userFileManager
.
FileAsset
=
await
photoFetchResult
.
getPositionObject
(
expectIndex
);
mgr
.
getPhotoIndex
(
photoAsset
.
uri
,
album
.
albumUri
,
fetchOptions
,
(
err
,
index
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
`getPhotoIndex successfully and index is :
${
index
}
`
);
...
...
@@ -1504,31 +1504,32 @@ getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promis
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
getPhotoIndexDemo
'
);
let
predicatesForGetAsset
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOp
=
{
let
predicatesForGetAsset
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOp
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicatesForGetAsset
};
// Obtain the uri of the album
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
FAVORITE
,
fetchOp
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
orderByAsc
(
userFileManager
.
ImageVideoKey
.
DATE_MODIFIED
);
let
fetchOptions
=
{
fetchColumns
:
[
userFileManager
.
ImageVideoKey
.
DATE_MODIFIED
],
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
FAVORITE
,
fetchOp
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
orderByAsc
(
userFileManager
.
ImageVideoKey
.
DATE_MODIFIED
.
toString
()
);
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[
userFileManager
.
ImageVideoKey
.
DATE_MODIFIED
.
toString
()
],
predicates
:
predicates
};
let
photoFetchResult
=
await
album
.
getPhotoAssets
(
fetchOptions
);
let
photoFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOptions
);
let
expectIndex
=
1
;
// Obtain the uri of the second file
let
photoAsset
=
await
photoFetchResult
.
getPositionObject
(
expectIndex
);
let
photoAsset
:
userFileManager
.
FileAsset
=
await
photoFetchResult
.
getPositionObject
(
expectIndex
);
mgr
.
getPhotoIndex
(
photoAsset
.
uri
,
album
.
albumUri
,
fetchOptions
).
then
((
index
)
=>
{
console
.
info
(
`getPhotoIndex successfully and index is :
${
index
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
info
(
`getPhotoIndex failed; error:
${
err
}
`
);
});
}
catch
(
error
)
{
...
...
@@ -1627,21 +1628,21 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
onDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}
let
onCallback1
=
(
changeData
)
=>
{
let
onCallback1
=
(
changeData
:
userFileManager
.
ChangeData
)
=>
{
console
.
info
(
'
onCallback1 success, changData:
'
+
JSON
.
stringify
(
changeData
));
//file had changed, do something
}
let
onCallback2
=
(
changeData
)
=>
{
let
onCallback2
=
(
changeData
:
userFileManager
.
ChangeData
)
=>
{
console
.
info
(
'
onCallback2 success, changData:
'
+
JSON
.
stringify
(
changeData
));
//file had changed, do something
}
...
...
@@ -1690,20 +1691,20 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
offDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}
let
onCallback1
=
(
changeData
)
=>
{
let
onCallback1
=
(
changeData
:
userFileManager
.
ChangeData
)
=>
{
console
.
info
(
'
onCallback1 on
'
);
}
let
onCallback2
=
(
changeData
)
=>
{
let
onCallback2
=
(
changeData
:
userFileManager
.
ChangeData
)
=>
{
console
.
info
(
'
onCallback2 on
'
);
}
// 注册onCallback1监听
...
...
@@ -1750,8 +1751,8 @@ async function example() {
// image file had changed, do something
});
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
fileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
fileAsset
:
userFileManager
.
FileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
console
.
info
(
'
createPhotoAsset file displayName
'
+
fileAsset
.
displayName
);
console
.
info
(
'
createPhotoAsset successfully
'
);
}
catch
(
err
)
{
...
...
@@ -1802,8 +1803,8 @@ async function example() {
});
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
fileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
let
fileAsset
:
userFileManager
.
FileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
console
.
info
(
'
createPhotoAsset file displayName
'
+
fileAsset
.
displayName
);
console
.
info
(
'
createPhotoAsset successfully
'
);
}
catch
(
err
)
{
...
...
@@ -1854,15 +1855,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
fileAssetGetDemo
'
);
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[
'
title
'
],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
title
=
userFileManager
.
ImageVideoKey
.
TITLE
;
let
fileAssetTitle
=
fileAsset
.
get
(
title
.
toString
());
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
let
title
:
userFileManager
.
ImageVideoKey
=
userFileManager
.
ImageVideoKey
.
TITLE
;
let
fileAssetTitle
:
userFileManager
.
MemberType
=
fileAsset
.
get
(
title
.
toString
());
console
.
info
(
'
fileAsset Get fileAssetTitle =
'
,
fileAssetTitle
);
}
catch
(
err
)
{
console
.
error
(
'
release failed. message =
'
,
err
);
...
...
@@ -1893,14 +1894,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
fileAssetSetDemo
'
);
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
displayName
=
userFileManager
.
ImageVideoKey
.
DISPLAY_NAME
.
toString
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
let
displayName
:
string
=
userFileManager
.
ImageVideoKey
.
DISPLAY_NAME
.
toString
();
fileAsset
.
set
(
displayName
,
'
newDisplayName1
'
);
}
catch
(
err
)
{
console
.
error
(
'
release failed. message =
'
,
err
);
...
...
@@ -1931,20 +1932,20 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
commitModifyDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
displayName
=
userFileManager
.
ImageVideoKey
.
DISPLAY_NAME
.
toString
();
let
fileAssetDisplayName
=
fileAsset
.
get
(
displayName
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
let
displayName
:
string
=
userFileManager
.
ImageVideoKey
.
DISPLAY_NAME
.
toString
();
let
fileAssetDisplayName
:
userFileManager
.
MemberType
=
fileAsset
.
get
(
displayName
);
console
.
info
(
'
fileAsset get fileAssetDisplayName =
'
,
fileAssetDisplayName
);
fileAsset
.
set
(
displayName
,
'
newDisplayName2
'
);
fileAsset
.
commitModify
((
err
)
=>
{
if
(
err
==
undefined
)
{
let
newFileAssetDisplayName
=
fileAsset
.
get
(
displayName
);
let
newFileAssetDisplayName
:
userFileManager
.
MemberType
=
fileAsset
.
get
(
displayName
);
console
.
info
(
'
fileAsset get newFileAssetDisplayName =
'
,
newFileAssetDisplayName
);
}
else
{
console
.
error
(
'
commitModify failed, message =
'
,
err
);
...
...
@@ -1976,20 +1977,20 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
commitModifyDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
let
displayName
=
userFileManager
.
ImageVideoKey
.
DISPLAY_NAME
.
toString
();
let
fileAssetDisplayNam
e
=
fileAsset
.
get
(
displayName
);
let
newFileAssetDisplayName
:
userFileManager
.
MemberTyp
e
=
fileAsset
.
get
(
displayName
);
console
.
info
(
'
fileAsset get fileAssetDisplayName =
'
,
fileAssetDisplayName
);
fileAsset
.
set
(
displayName
,
'
newDisplayName3
'
);
try
{
await
fileAsset
.
commitModify
();
let
newFileAssetDisplayName
=
fileAsset
.
get
(
displayName
);
let
newFileAssetDisplayName
:
userFileManager
.
MemberType
=
fileAsset
.
get
(
displayName
);
console
.
info
(
'
fileAsset get newFileAssetDisplayName =
'
,
newFileAssetDisplayName
);
}
catch
(
err
)
{
console
.
error
(
'
release failed. message =
'
,
err
);
...
...
@@ -2021,8 +2022,8 @@ open(mode: string, callback: AsyncCallback<number>): void
```
ts
async
function
example
()
{
console
.
info
(
'
openDemo
'
);
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
fileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
fileAsset
:
userFileManager
.
FileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
fileAsset
.
open
(
'
rw
'
,
(
err
,
fd
)
=>
{
if
(
fd
!=
undefined
)
{
console
.
info
(
'
File fd
'
+
fd
);
...
...
@@ -2064,9 +2065,9 @@ open(mode: string): Promise<number>
async
function
example
()
{
console
.
info
(
'
openDemo
'
);
try
{
let
testFileName
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
fileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
let
fd
=
await
fileAsset
.
open
(
'
rw
'
);
let
testFileName
:
string
=
'
testFile
'
+
Date
.
now
()
+
'
.jpg
'
;
const
fileAsset
:
userFileManager
.
FileAsset
=
await
mgr
.
createPhotoAsset
(
testFileName
);
let
fd
:
number
=
await
fileAsset
.
open
(
'
rw
'
);
if
(
fd
!=
undefined
)
{
console
.
info
(
'
File fd
'
+
fd
);
fileAsset
.
close
(
fd
);
...
...
@@ -2102,14 +2103,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
closeDemo
'
);
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fd
=
await
fileAsset
.
open
(
'
rw
'
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
let
fd
:
number
=
await
fileAsset
.
open
(
'
rw
'
);
console
.
info
(
'
file fd
'
,
fd
);
fileAsset
.
close
(
fd
,
(
err
)
=>
{
if
(
err
==
undefined
)
{
...
...
@@ -2152,14 +2153,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
closeDemo
'
);
try
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
let
fd
=
await
asset
.
open
(
'
rw
'
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
let
fd
:
number
=
await
asset
.
open
(
'
rw
'
);
console
.
info
(
'
file fd
'
,
fd
);
await
asset
.
close
(
fd
);
console
.
info
(
'
asset close succeed.
'
);
...
...
@@ -2192,13 +2193,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getThumbnailDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
a
sset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileA
sset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
asset displayName =
'
,
asset
.
displayName
);
asset
.
getThumbnail
((
err
,
pixelMap
)
=>
{
if
(
err
==
undefined
)
{
...
...
@@ -2231,17 +2232,18 @@ getThumbnail(size: image.Size, callback: AsyncCallback<image.PixelMap>): v
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
image
from
'
@ohos.multimedia.image
'
;
async
function
example
()
{
console
.
info
(
'
getThumbnailDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
size
=
{
width
:
720
,
height
:
720
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
let
size
:
image
.
Size
=
{
width
:
720
,
height
:
720
};
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
asset displayName =
'
,
asset
.
displayName
);
asset
.
getThumbnail
(
size
,
(
err
,
pixelMap
)
=>
{
if
(
err
==
undefined
)
{
...
...
@@ -2279,21 +2281,23 @@ getThumbnail(size?: image.Size): Promise<image.PixelMap>
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
image
from
'
@ohos.multimedia.image
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
getThumbnailDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
size
=
{
width
:
720
,
height
:
720
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
let
size
:
image
.
Size
=
{
width
:
720
,
height
:
720
};
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
asset displayName =
'
,
asset
.
displayName
);
asset
.
getThumbnail
(
size
).
then
((
pixelMap
)
=>
{
console
.
info
(
'
getThumbnail successful
'
+
pixelMap
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
getThumbnail fail
'
+
err
);
});
}
...
...
@@ -2323,13 +2327,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
favoriteDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
asset
.
favorite
(
true
,
(
err
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
'
favorite successfully
'
);
...
...
@@ -2366,19 +2370,20 @@ favorite(isFavorite: boolean): Promise<void>
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
favoriteDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
asset
.
favorite
(
true
).
then
(
function
()
{
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
asset
.
favorite
(
true
).
then
(
()
=>
{
console
.
info
(
'
favorite successfully
'
);
}).
catch
(
function
(
err
)
{
}).
catch
(
(
err
:
BusinessError
)
=>
{
console
.
error
(
'
favorite failed with error:
'
+
err
);
});
}
...
...
@@ -2419,13 +2424,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
setHiddenDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
asset
.
setHidden
(
true
,
(
err
)
=>
{
if
(
err
==
undefined
)
{
console
.
info
(
'
setHidden successfully
'
);
...
...
@@ -2473,22 +2478,23 @@ setHidden(hiddenState: boolean): Promise<void>
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
// 示例代码为将文件从隐藏相册中恢复,需要先在隐藏相册预置资源
console
.
info
(
'
setHiddenDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumList
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
HIDDEN
);
const
album
=
await
albumList
.
getFirstObject
();
let
fetchResult
=
await
album
.
getPhotoAssets
(
fetchOption
);
const
asset
=
await
fetchResult
.
getFirstObject
();
let
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
HIDDEN
);
const
album
:
userFileManager
.
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOption
);
const
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
asset
.
setHidden
(
false
).
then
(()
=>
{
console
.
info
(
'
setHidden successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
setHidden failed with error:
'
+
err
);
});
}
...
...
@@ -2564,18 +2570,18 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
getExifDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
isNotNull
(
'
all_exif
'
)
let
fetchOptions
=
{
fetchColumns
:
[
'
all_exif
'
,
userFileManager
.
ImageVideoKey
.
USER_COMMENT
],
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
isNotNull
(
'
all_exif
'
)
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[
'
all_exif
'
,
userFileManager
.
ImageVideoKey
.
USER_COMMENT
.
toString
()
],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getExifDemo fileAsset displayName:
'
+
JSON
.
stringify
(
fileAsset
.
displayName
));
let
exifMessage
=
await
fileAsset
.
getExif
();
let
userCommentKey
=
'
UserComment
'
;
let
userComment
=
JSON
.
stringify
(
JSON
.
parse
(
exifMessage
),
[
userCommentKey
]);
let
exifMessage
:
string
=
await
fileAsset
.
getExif
();
let
userCommentKey
:
string
=
'
UserComment
'
;
let
userComment
:
string
=
JSON
.
stringify
(
JSON
.
parse
(
exifMessage
),
[
userCommentKey
]);
console
.
info
(
'
getExifDemo userComment:
'
+
JSON
.
stringify
(
userComment
));
fetchResult
.
close
();
}
catch
(
err
)
{
...
...
@@ -2654,19 +2660,19 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
getExifDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
predicates
.
isNotNull
(
'
all_exif
'
)
let
fetchOptions
=
{
fetchColumns
:
[
'
all_exif
'
,
userFileManager
.
ImageVideoKey
.
USER_COMMENT
],
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[
'
all_exif
'
,
userFileManager
.
ImageVideoKey
.
USER_COMMENT
.
toString
()
],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
getExifDemo fileAsset displayName:
'
+
JSON
.
stringify
(
fileAsset
.
displayName
));
let
userCommentKey
=
'
UserComment
'
;
let
userCommentKey
:
string
=
'
UserComment
'
;
fileAsset
.
getExif
((
err
,
exifMessage
)
=>
{
if
(
exifMessage
!=
undefined
)
{
let
userComment
=
JSON
.
stringify
(
JSON
.
parse
(
exifMessage
),
[
userCommentKey
]);
let
userComment
:
string
=
JSON
.
stringify
(
JSON
.
parse
(
exifMessage
),
[
userCommentKey
]);
console
.
info
(
'
getExifDemo userComment:
'
+
JSON
.
stringify
(
userComment
));
}
else
{
console
.
error
(
'
getExif failed, message =
'
,
err
);
...
...
@@ -2713,14 +2719,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
setUserCommentDemo
'
)
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
userComment
=
'
test_set_user_comment
'
;
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
let
userComment
:
string
=
'
test_set_user_comment
'
;
await
fileAsset
.
setUserComment
(
userComment
);
}
catch
(
err
)
{
console
.
error
(
'
setUserCommentDemoCallback failed with error:
'
+
err
);
...
...
@@ -2757,14 +2763,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
setUserCommentDemo
'
)
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOptions
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
userComment
=
'
test_set_user_comment
'
;
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOptions
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
let
userComment
:
string
=
'
test_set_user_comment
'
;
fileAsset
.
setUserComment
(
userComment
,
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
setUserComment successfully
'
);
...
...
@@ -2803,13 +2809,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getCountDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
fetchCount
=
fetchResult
.
getCount
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
fetchCount
:
number
=
fetchResult
.
getCount
();
console
.
info
(
'
fetchCount =
'
,
fetchCount
);
}
```
...
...
@@ -2834,15 +2840,15 @@ isAfterLast(): boolean
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
async
function
example
()
{
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
fetchCount
=
fetchResult
.
getCount
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
const
fetchCount
:
number
=
fetchResult
.
getCount
();
console
.
info
(
'
count:
'
+
fetchCount
);
let
fileAsset
=
await
fetchResult
.
getLastObject
();
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getLastObject
();
if
(
fetchResult
.
isAfterLast
())
{
console
.
info
(
'
fileAsset isAfterLast displayName =
'
,
fileAsset
.
displayName
);
}
else
{
...
...
@@ -2866,13 +2872,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
fetchResultCloseDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
try
{
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
await
fetchResult
.
close
();
console
.
info
(
'
close succeed.
'
);
}
catch
(
err
)
{
...
...
@@ -2902,12 +2908,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getFirstObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
fetchResult
.
getFirstObject
((
err
,
fileAsset
)
=>
{
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset displayName:
'
,
fileAsset
.
displayName
);
...
...
@@ -2939,13 +2945,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getFirstObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
=
await
fetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
console
.
info
(
'
fileAsset displayName:
'
,
fileAsset
.
displayName
);
}
```
...
...
@@ -2971,12 +2977,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getNextObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
await
fetchResult
.
getFirstObject
();
if
(
fetchResult
.
isAfterLast
())
{
fetchResult
.
getNextObject
((
err
,
fileAsset
)
=>
{
...
...
@@ -3011,15 +3017,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getNextObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
await
fetchResult
.
getFirstObject
();
if
(
fetchResult
.
isAfterLast
())
{
let
fileAsset
=
await
fetchResult
.
getNextObject
();
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getNextObject
();
console
.
info
(
'
fileAsset displayName:
'
,
fileAsset
.
displayName
);
}
}
...
...
@@ -3046,12 +3052,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getLastObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
fetchResult
.
getLastObject
((
err
,
fileAsset
)
=>
{
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset displayName:
'
,
fileAsset
.
displayName
);
...
...
@@ -3083,13 +3089,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getLastObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
=
await
fetchResult
.
getLastObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getLastObject
();
console
.
info
(
'
fileAsset displayName:
'
,
fileAsset
.
displayName
);
}
```
...
...
@@ -3124,12 +3130,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getPositionObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
fetchResult
.
getPositionObject
(
0
,
(
err
,
fileAsset
)
=>
{
if
(
fileAsset
!=
undefined
)
{
console
.
info
(
'
fileAsset displayName:
'
,
fileAsset
.
displayName
);
...
...
@@ -3175,13 +3181,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getPositionObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
=
await
fetchResult
.
getPositionObject
(
0
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getPositionObject
(
0
);
console
.
info
(
'
fileAsset displayName:
'
,
fileAsset
.
displayName
);
}
```
...
...
@@ -3207,12 +3213,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getAllObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
fetchResult
.
getAllObject
((
err
,
fileAssetList
)
=>
{
if
(
fileAssetList
!=
undefined
)
{
console
.
info
(
'
fileAssetList length:
'
,
fileAssetList
.
length
);
...
...
@@ -3244,13 +3250,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
getAllObjectDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAssetList
=
await
fetchResult
.
getAllObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
fileAssetList
:
Array
<
userFileManager
.
FileAsset
>
=
await
fetchResult
.
getAllObject
();
console
.
info
(
'
fileAssetList length:
'
,
fileAssetList
.
length
);
}
```
...
...
@@ -3305,16 +3311,16 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
albumGetFileAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
userFileManager
.
AlbumFetchOptions
=
{
predicates
:
predicates
};
let
fetchOption
=
{
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
albumList
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
const
a
lbum
=
await
albumList
.
getFirstObject
();
let
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
let
album
:
userFileManager
.
A
lbum
=
await
albumList
.
getFirstObject
();
album
.
getPhotoAssets
(
fetchOption
,
(
err
,
albumFetchResult
)
=>
{
if
(
albumFetchResult
!=
undefined
)
{
console
.
info
(
'
album getPhotoAssets successfully, getCount:
'
+
albumFetchResult
.
getCount
());
...
...
@@ -3359,23 +3365,24 @@ getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>&g
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
albumGetFileAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
userFileManager
.
AlbumFetchOptions
=
{
predicates
:
predicates
};
let
fetchOption
=
{
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
albumList
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
const
album
=
await
albumList
.
getFirstObject
();
const
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
const
album
:
userFileManager
.
Album
=
await
albumList
.
getFirstObject
();
album
.
getPhotoAssets
(
fetchOption
).
then
((
albumFetchResult
)
=>
{
console
.
info
(
'
album getFileAssets successfully, getCount:
'
+
albumFetchResult
.
getCount
());
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album getFileAssets failed with error:
'
+
err
);
});
}
...
...
@@ -3404,12 +3411,12 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
albumCommitModifyDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
userFileManager
.
AlbumFetchOptions
=
{
predicates
:
predicates
};
const
albumList
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
const
album
=
await
albumList
.
getFirstObject
();
const
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
const
album
:
userFileManager
.
Album
=
await
albumList
.
getFirstObject
();
album
.
albumName
=
'
hello
'
;
album
.
commitModify
((
err
)
=>
{
if
(
err
!=
undefined
)
{
...
...
@@ -3441,25 +3448,26 @@ commitModify(): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
albumCommitModifyDemo
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
albumFetchOptions
:
userFileManager
.
AlbumFetchOptions
=
{
predicates
:
predicates
};
try
{
var
albumList
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
let
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getPhotoAlbums
(
albumFetchOptions
);
let
album
:
userFileManager
.
Album
=
await
albumList
.
getFirstObject
();
album
.
albumName
=
'
hello
'
;
album
.
commitModify
().
then
(()
=>
{
console
.
info
(
'
commitModify successfully
'
);
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
commitModify failed with error:
'
+
err
);
});
}
catch
(
err
)
{
console
.
error
(
'
getPhotoAlbums failed. message =
'
,
err
);
}
const
album
=
await
albumList
.
getFirstObject
();
album
.
albumName
=
'
hello
'
;
album
.
commitModify
().
then
(()
=>
{
console
.
info
(
'
commitModify successfully
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
commitModify failed with error:
'
+
err
);
});
}
```
...
...
@@ -3496,15 +3504,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
addPhotoAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
album
.
addPhotoAssets
([
asset
],
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album addPhotoAssets successfully
'
);
...
...
@@ -3552,22 +3560,23 @@ addPhotoAssets(assets: Array<FileAsset>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
addPhotoAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
mgr
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
album
.
addPhotoAssets
([
asset
]).
then
(()
=>
{
console
.
info
(
'
album addPhotoAssets successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album addPhotoAssets failed with error:
'
+
err
);
});
}
catch
(
err
)
{
...
...
@@ -3609,15 +3618,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
removePhotoAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
album
.
removePhotoAssets
([
asset
],
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album removePhotoAssets successfully
'
);
...
...
@@ -3665,22 +3674,23 @@ removePhotoAssets(assets: Array<FileAsset>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
removePhotoAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
USER
,
userFileManager
.
AlbumSubType
.
USER_GENERIC
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
album
.
removePhotoAssets
([
asset
]).
then
(()
=>
{
console
.
info
(
'
album removePhotoAssets successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album removePhotoAssets failed with error:
'
+
err
);
});
}
catch
(
err
)
{
...
...
@@ -3722,15 +3732,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
recoverPhotoAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
TRASH
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
TRASH
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
album
.
recoverPhotoAssets
([
asset
],
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album recoverPhotoAssets successfully
'
);
...
...
@@ -3778,22 +3788,23 @@ recoverPhotoAssets(assets: Array<FileAsset>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
recoverPhotoAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
TRASH
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
TRASH
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
album
.
recoverPhotoAssets
([
asset
]).
then
(()
=>
{
console
.
info
(
'
album recoverPhotoAssets successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album recoverPhotoAssets failed with error:
'
+
err
);
});
}
catch
(
err
)
{
...
...
@@ -3837,15 +3848,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
try
{
console
.
info
(
'
deletePhotoAssetsDemoCallback
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
TRASH
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
TRASH
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
album
.
deletePhotoAssets
([
asset
],
(
err
)
=>
{
if
(
err
===
undefined
)
{
console
.
info
(
'
album deletePhotoAssets successfully
'
);
...
...
@@ -3895,22 +3906,23 @@ deletePhotoAssets(assets: Array<FileAsset>): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
try
{
console
.
info
(
'
deletePhotoAssetsDemoPromise
'
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
let
albumFetchResult
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
TRASH
);
let
album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
=
await
fetchResult
.
getFirstObject
();
let
albumFetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
Album
>
=
await
mgr
.
getAlbums
(
userFileManager
.
AlbumType
.
SYSTEM
,
userFileManager
.
AlbumSubType
.
TRASH
);
let
album
:
userFileManager
.
Album
=
await
albumFetchResult
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
album
.
getPhotoAssets
(
fetchOption
);
let
asset
:
userFileManager
.
FileAsset
=
await
fetchResult
.
getFirstObject
();
album
.
deletePhotoAssets
([
asset
]).
then
(()
=>
{
console
.
info
(
'
album deletePhotoAssets successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
album deletePhotoAssets failed with error:
'
+
err
);
});
}
catch
(
err
)
{
...
...
@@ -3971,13 +3983,13 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
privateAlbumGetFileAssetsDemoCallback
'
);
let
albumList
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
PrivateAlbum
>
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
trashAlbum
=
await
albumList
.
getFirstObject
();
const
trashAlbum
:
userFileManager
.
PrivateAlbum
=
await
albumList
.
getFirstObject
();
trashAlbum
.
getPhotoAssets
(
fetchOption
,
(
err
,
fetchResult
)
=>
{
if
(
fetchResult
!=
undefined
)
{
let
count
=
fetchResult
.
getCount
();
...
...
@@ -4029,14 +4041,14 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
privateAlbumGetFileAssetsDemoPromise
'
);
let
albumList
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
PrivateAlbum
>
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
trashAlbum
=
await
albumList
.
getFirstObject
();
let
fetchResult
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
const
trashAlbum
:
userFileManager
.
PrivateAlbum
=
await
albumList
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
let
count
=
fetchResult
.
getCount
();
console
.
info
(
'
fetchResult.count =
'
,
count
);
}
...
...
@@ -4068,15 +4080,15 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
privateAlbumDeleteCallback
'
);
let
albumList
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
PrivateAlbum
>
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
trash
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
const
f
ileAsset
=
await
fetchResult
.
getFirstObject
();
let
trashAlbum
:
userFileManager
.
Private
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
F
ileAsset
=
await
fetchResult
.
getFirstObject
();
let
deleteFileUri
=
fileAsset
.
uri
;
trashAlbum
.
delete
(
deleteFileUri
,
(
err
)
=>
{
if
(
err
!=
undefined
)
{
...
...
@@ -4116,22 +4128,22 @@ delete(uri: string): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
privateAlbumDeleteDemoPromise
'
);
let
albumList
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
albumListlet
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
PrivateAlbum
>
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
trash
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
const
f
ileAsset
=
await
fetchResult
.
getFirstObject
();
let
trashAlbum
:
userFileManager
.
Private
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
F
ileAsset
=
await
fetchResult
.
getFirstObject
();
let
deleteFileUri
=
fileAsset
.
uri
;
trashAlbum
.
delete
(
deleteFileUri
).
then
(()
=>
{
console
.
info
(
'
trashAlbum.delete successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
trashAlbum.delete failed, message =
'
,
err
);
});
}
...
...
@@ -4163,16 +4175,16 @@ import dataSharePredicates from '@ohos.data.dataSharePredicates';
async
function
example
()
{
console
.
info
(
'
privateAlbumRecoverDemoCallback
'
);
let
albumList
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
PrivateAlbum
>
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
trash
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
const
f
ileAsset
=
await
fetchResult
.
getFirstObject
();
let
recoverFileUri
=
fileAsset
.
uri
;
let
trashAlbum
:
userFileManager
.
Private
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
F
ileAsset
=
await
fetchResult
.
getFirstObject
();
let
recoverFileUri
:
string
=
fileAsset
.
uri
;
trashAlbum
.
recover
(
recoverFileUri
,
(
err
)
=>
{
if
(
err
!=
undefined
)
{
console
.
error
(
'
trashAlbum.recover failed, message =
'
,
err
);
...
...
@@ -4211,22 +4223,23 @@ recover(uri: string): Promise<void>;
```
ts
import
dataSharePredicates
from
'
@ohos.data.dataSharePredicates
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
console
.
info
(
'
privateAlbumRecoverDemoPromise
'
);
let
albumList
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
=
{
let
albumList
:
userFileManager
.
FetchResult
<
userFileManager
.
PrivateAlbum
>
=
await
mgr
.
getPrivateAlbum
(
userFileManager
.
PrivateAlbumType
.
TYPE_TRASH
);
let
predicates
:
dataSharePredicates
.
DataSharePredicates
=
new
dataSharePredicates
.
DataSharePredicates
();
let
fetchOption
:
userFileManager
.
FetchOptions
=
{
fetchColumns
:
[],
predicates
:
predicates
};
const
trash
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
const
f
ileAsset
=
await
fetchResult
.
getFirstObject
();
let
recoverFileUri
=
fileAsset
.
uri
;
let
trashAlbum
:
userFileManager
.
Private
Album
=
await
albumList
.
getFirstObject
();
let
fetchResult
:
userFileManager
.
FetchResult
<
userFileManager
.
FileAsset
>
=
await
trashAlbum
.
getPhotoAssets
(
fetchOption
);
let
fileAsset
:
userFileManager
.
F
ileAsset
=
await
fetchResult
.
getFirstObject
();
let
recoverFileUri
:
string
=
fileAsset
.
uri
;
trashAlbum
.
recover
(
recoverFileUri
).
then
(()
=>
{
console
.
info
(
'
trashAlbum.recover successfully
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
trashAlbum.recover failed, message =
'
,
err
);
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录