1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { AsyncCallback, Callback } from './basic'; 17import Context from './application/Context'; 18import image from './@ohos.multimedia.image'; 19import dataSharePredicates from './@ohos.data.dataSharePredicates'; 20 21/** 22 * @name userFileManager 23 * @since 9 24 * @systemapi 25 * @syscap SystemCapability.FileManagement.UserFileManager.Core 26 */ 27declare namespace userFileManager { 28 /** 29 * Returns an instance of UserFileManager 30 * @since 9 31 * @systemapi 32 * @syscap SystemCapability.FileManagement.UserFileManager.Core 33 * @StageModelOnly 34 * @param context Hap context information 35 * @returns Instance of UserFileManager 36 */ 37 function getUserFileMgr(context: Context): UserFileManager; 38 39 /** 40 * Enumeration types for different kinds of Files 41 * @since 9 42 * @systemapi 43 * @syscap SystemCapability.FileManagement.UserFileManager.Core 44 */ 45 enum FileType { 46 /** 47 * Image file type 48 * @since 9 49 * @systemapi 50 * @syscap SystemCapability.FileManagement.UserFileManager.Core 51 */ 52 IMAGE = 1, 53 /** 54 * Video file type 55 * @since 9 56 * @systemapi 57 * @syscap SystemCapability.FileManagement.UserFileManager.Core 58 */ 59 VIDEO, 60 /** 61 * Audio file type 62 * @since 9 63 * @systemapi 64 * @syscap SystemCapability.FileManagement.UserFileManager.Core 65 */ 66 AUDIO 67 } 68 69 /** 70 * Indicates the type of file asset member. 71 * @since 9 72 * @systemapi 73 */ 74 type MemberType = number | string | boolean; 75 76 /** 77 * Indicates the type of notify event. 78 * @since 9 79 * @systemapi 80 */ 81 type ChangeEvent = 'deviceChange' | 'albumChange' | 'imageChange' | 'audioChange' | 'videoChange' | 'remoteFileChange'; 82 83 /** 84 * Provides methods to encapsulate file attributes. 85 * @since 9 86 * @systemapi 87 * @syscap SystemCapability.FileManagement.UserFileManager.Core 88 */ 89 interface FileAsset { 90 /** 91 * URI of the file. 92 * @since 9 93 * @systemapi 94 * @syscap SystemCapability.FileManagement.UserFileManager.Core 95 */ 96 readonly uri: string; 97 /** 98 * File type, for example, IMAGE, VIDEO, AUDIO 99 * @since 9 100 * @systemapi 101 * @syscap SystemCapability.FileManagement.UserFileManager.Core 102 */ 103 readonly fileType: FileType; 104 /** 105 * Display name (with a file name extension) of the file. 106 * @since 9 107 * @systemapi 108 * @syscap SystemCapability.FileManagement.UserFileManager.Core 109 */ 110 displayName: string; 111 /** 112 * Return the fileAsset member parameter. 113 * @since 9 114 * @systemapi 115 * @syscap SystemCapability.FileManagement.UserFileManager.Core 116 * @param member the name of the parameter. for example : get(ImageVideoKey.URI) 117 */ 118 get(member: string): MemberType; 119 /** 120 * Set the fileAsset member parameter. 121 * @since 9 122 * @systemapi 123 * @syscap SystemCapability.FileManagement.UserFileManager.Core 124 * @param member The name of the parameter. only TITLE can be changed 125 * @param string The value of the parameter. 126 * @example : Set(ImageVideoKey.TITLE, "newTitle"), call commitModify after set value 127 */ 128 set(member: string, value: string): void; 129 /** 130 * Modify meta data where the file is located. 131 * @since 9 132 * @systemapi 133 * @syscap SystemCapability.FileManagement.UserFileManager.Core 134 * @permission ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 135 * @param callback No value will be returned. 136 */ 137 commitModify(callback: AsyncCallback<void>): void; 138 /** 139 * Modify meta data where the file is located. 140 * @since 9 141 * @systemapi 142 * @syscap SystemCapability.FileManagement.UserFileManager.Core 143 * @permission ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 144 */ 145 commitModify(): Promise<void>; 146 /** 147 * Open the file is located. 148 * @since 9 149 * @systemapi 150 * @syscap SystemCapability.FileManagement.UserFileManager.Core 151 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO or ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 152 * @param mode Mode for open, for example: rw, r, w. 153 * @param callback Callback return the fd of the file. 154 */ 155 open(mode: string, callback: AsyncCallback<number>): void; 156 /** 157 * Open the file is located. 158 * @since 9 159 * @systemapi 160 * @syscap SystemCapability.FileManagement.UserFileManager.Core 161 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO or ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 162 * @param mode Mode for open, for example: rw, r, w. 163 */ 164 open(mode: string): Promise<number>; 165 /** 166 * Close the file is located. 167 * @since 9 168 * @systemapi 169 * @syscap SystemCapability.FileManagement.UserFileManager.Core 170 * @param fd Fd of the file which had been opened 171 * @param callback No value will be returned. 172 */ 173 close(fd: number, callback: AsyncCallback<void>): void; 174 /** 175 * Close the file is located. 176 * @since 9 177 * @systemapi 178 * @syscap SystemCapability.FileManagement.UserFileManager.Core 179 * @param fd Fd of the file which had been opened 180 */ 181 close(fd: number): Promise<void>; 182 /** 183 * Get thumbnail of the file when the file is located. 184 * @since 9 185 * @systemapi 186 * @syscap SystemCapability.FileManagement.UserFileManager.Core 187 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 188 * @param callback Callback used to return the thumbnail's pixelMap. 189 */ 190 getThumbnail(callback: AsyncCallback<image.PixelMap>): void; 191 /** 192 * Get thumbnail of the file when the file is located. 193 * @since 9 194 * @systemapi 195 * @syscap SystemCapability.FileManagement.UserFileManager.Core 196 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 197 * @param size Thumbnail's size 198 * @param callback Callback used to return the thumbnail's pixelMap. 199 */ 200 getThumbnail(size: image.Size, callback: AsyncCallback<image.PixelMap>): void; 201 /** 202 * Get thumbnail of the file when the file is located. 203 * @since 9 204 * @systemapi 205 * @syscap SystemCapability.FileManagement.UserFileManager.Core 206 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 207 * @param size Thumbnail's size 208 */ 209 getThumbnail(size?: image.Size): Promise<image.PixelMap>; 210 /** 211 * Set favorite for the file when the file is located. 212 * @since 9 213 * @systemapi 214 * @syscap SystemCapability.FileManagement.UserFileManager.Core 215 * @permission ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 216 * @param isFavorite True is favorite file, false is not favorite file 217 * @param callback Callback used to return, No value is returned. 218 */ 219 favorite(isFavorite: boolean, callback: AsyncCallback<void>): void; 220 /** 221 * Set favorite for the file when the file is located. 222 * @since 9 223 * @systemapi 224 * @syscap SystemCapability.FileManagement.UserFileManager.Core 225 * @permission ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 226 * @param isFavorite True is favorite file, false is not favorite file 227 */ 228 favorite(isFavorite: boolean): Promise<void>; 229 } 230 231 /** 232 * Describes AUDIO TYPE FetchOptions's predicate 233 * @since 9 234 * @systemapi 235 * @syscap SystemCapability.FileManagement.UserFileManager.Core 236 */ 237 enum AudioKey { 238 /** 239 * File uri 240 * @since 9 241 * @systemapi 242 * @syscap SystemCapability.FileManagement.UserFileManager.Core 243 */ 244 URI, 245 /** 246 * File name 247 * @since 9 248 * @systemapi 249 * @syscap SystemCapability.FileManagement.UserFileManager.Core 250 */ 251 DISPLAY_NAME, 252 /** 253 * Date of the file creation 254 * @since 9 255 * @systemapi 256 * @syscap SystemCapability.FileManagement.UserFileManager.Core 257 */ 258 DATE_ADDED, 259 /** 260 * Modify date of the file 261 * @since 9 262 * @systemapi 263 * @syscap SystemCapability.FileManagement.UserFileManager.Core 264 */ 265 DATE_MODIFIED, 266 /** 267 * Title of the file 268 * @since 9 269 * @systemapi 270 * @syscap SystemCapability.FileManagement.UserFileManager.Core 271 */ 272 TITLE, 273 /** 274 * Artist of the audio file 275 * @since 9 276 * @systemapi 277 * @syscap SystemCapability.FileManagement.UserFileManager.Core 278 */ 279 ARTIST, 280 /** 281 * Audio album of the audio file 282 * @since 9 283 * @systemapi 284 * @syscap SystemCapability.FileManagement.UserFileManager.Core 285 */ 286 AUDIOALBUM, 287 /** 288 * Duration of the audio file 289 * @since 9 290 * @systemapi 291 * @syscap SystemCapability.FileManagement.UserFileManager.Core 292 */ 293 DURATION, 294 /** 295 * Favorite state of the file 296 * @since 9 297 * @systemapi 298 * @syscap SystemCapability.FileManagement.UserFileManager.Core 299 */ 300 FAVORITE 301 } 302 303 /** 304 * Describes Image, Video TYPE FetchOptions's predicate 305 * @since 9 306 * @systemapi 307 * @syscap SystemCapability.FileManagement.UserFileManager.Core 308 */ 309 enum ImageVideoKey { 310 /** 311 * File uri 312 * @since 9 313 * @systemapi 314 * @syscap SystemCapability.FileManagement.UserFileManager.Core 315 */ 316 URI, 317 /** 318 * File type of the Asset 319 * @since 9 320 * @systemapi 321 * @syscap SystemCapability.FileManagement.UserFileManager.Core 322 */ 323 FILE_TYPE, 324 /** 325 * File name 326 * @since 9 327 * @systemapi 328 * @syscap SystemCapability.FileManagement.UserFileManager.Core 329 */ 330 DISPLAY_NAME, 331 /** 332 * Date of the file creation 333 * @since 9 334 * @systemapi 335 * @syscap SystemCapability.FileManagement.UserFileManager.Core 336 */ 337 DATE_ADDED, 338 /** 339 * Modify date of the file 340 * @since 9 341 * @systemapi 342 * @syscap SystemCapability.FileManagement.UserFileManager.Core 343 */ 344 DATE_MODIFIED, 345 /** 346 * Title of the file 347 * @since 9 348 * @systemapi 349 * @syscap SystemCapability.FileManagement.UserFileManager.Core 350 */ 351 TITLE, 352 /** 353 * Duration of the audio and video file 354 * @since 9 355 * @systemapi 356 * @syscap SystemCapability.FileManagement.UserFileManager.Core 357 */ 358 DURATION, 359 /** 360 * Width of the image file 361 * @since 9 362 * @systemapi 363 * @syscap SystemCapability.FileManagement.UserFileManager.Core 364 */ 365 WIDTH, 366 /** 367 * Height of the image file 368 * @since 9 369 * @systemapi 370 * @syscap SystemCapability.FileManagement.UserFileManager.Core 371 */ 372 HEIGHT, 373 /** 374 * Date taken of the file 375 * @since 9 376 * @systemapi 377 * @syscap SystemCapability.FileManagement.UserFileManager.Core 378 */ 379 DATE_TAKEN, 380 /** 381 * Orientation of the image file 382 * @since 9 383 * @systemapi 384 * @syscap SystemCapability.FileManagement.UserFileManager.Core 385 */ 386 ORIENTATION, 387 /** 388 * Favorite state of the file 389 * @since 9 390 * @systemapi 391 * @syscap SystemCapability.FileManagement.UserFileManager.Core 392 */ 393 FAVORITE 394 } 395 396 /** 397 * Describes Album TYPE predicate 398 * @since 9 399 * @systemapi 400 * @syscap SystemCapability.FileManagement.UserFileManager.Core 401 */ 402 enum AlbumKey { 403 /** 404 * Album uri 405 * @since 9 406 * @systemapi 407 * @syscap SystemCapability.FileManagement.UserFileManager.Core 408 */ 409 URI, 410 /** 411 * File type of the Album 412 * @since 9 413 * @systemapi 414 * @syscap SystemCapability.FileManagement.UserFileManager.Core 415 */ 416 FILE_TYPE, 417 /** 418 * Album name 419 * @since 9 420 * @systemapi 421 * @syscap SystemCapability.FileManagement.UserFileManager.Core 422 */ 423 ALBUM_NAME, 424 /** 425 * Date of the Album creation 426 * @since 9 427 * @systemapi 428 * @syscap SystemCapability.FileManagement.UserFileManager.Core 429 */ 430 DATE_ADDED, 431 /** 432 * Modify date of the Album 433 * @since 9 434 * @systemapi 435 * @syscap SystemCapability.FileManagement.UserFileManager.Core 436 */ 437 DATE_MODIFIED 438 } 439 440 /** 441 * Fetch parameters 442 * @since 9 443 * @systemapi 444 * @syscap SystemCapability.FileManagement.UserFileManager.Core 445 */ 446 interface FetchOptions { 447 /** 448 * Indicates the columns to query. 449 * @since 9 450 * @systemapi 451 * @syscap SystemCapability.FileManagement.UserFileManager.Core 452 * @param fetchColumns Indicates the columns to query. If this parameter is null, only uri, name, fileType will query. 453 */ 454 fetchColumns: Array<string>; 455 /** 456 * Predicate to query 457 * @since 9 458 * @systemapi 459 * @syscap SystemCapability.FileManagement.UserFileManager.Core 460 * @param predicates Indicates filter criteria. 461 */ 462 predicates: dataSharePredicates.DataSharePredicates; 463 } 464 465 /** 466 * Fetch parameters 467 * @since 9 468 * @systemapi 469 * @syscap SystemCapability.FileManagement.UserFileManager.Core 470 */ 471 interface AlbumFetchOptions { 472 /** 473 * Predicate to query 474 * @since 9 475 * @systemapi 476 * @syscap SystemCapability.FileManagement.UserFileManager.Core 477 * @param predicates Indicates filter criteria. 478 */ 479 predicates: dataSharePredicates.DataSharePredicates; 480 } 481 482 /** 483 * Implements file retrieval. 484 * @since 9 485 * @systemapi 486 * @syscap SystemCapability.FileManagement.UserFileManager.Core 487 */ 488 interface FetchResult<T> { 489 /** 490 * Obtains the total number of files in the file retrieval result. 491 * @since 9 492 * @systemapi 493 * @syscap SystemCapability.FileManagement.UserFileManager.Core 494 * @returns Total number of files. 495 */ 496 getCount(): number; 497 /** 498 * Checks whether the result set points to the last row. 499 * @since 9 500 * @systemapi 501 * @syscap SystemCapability.FileManagement.UserFileManager.Core 502 * @returns Whether the file is the last one. 503 * You need to check whether the file is the last one before calling getNextObject, 504 * which returns the next file only when False is returned for this method. 505 */ 506 isAfterLast(): boolean; 507 /** 508 * Releases the FetchResult instance and invalidates it. Other methods cannot be called. 509 * @since 9 510 * @systemapi 511 * @syscap SystemCapability.FileManagement.UserFileManager.Core 512 */ 513 close(): void; 514 /** 515 * Obtains the first FileAsset in the file retrieval result. This method uses a callback to return the file. 516 * @since 9 517 * @systemapi 518 * @syscap SystemCapability.FileManagement.UserFileManager.Core 519 * @param callback Callback used to return the file in the format of a FileAsset instance. 520 */ 521 getFirstObject(callback: AsyncCallback<T>): void; 522 /** 523 * Obtains the first T in the file retrieval result. This method uses a promise to return the file. 524 * @since 9 525 * @systemapi 526 * @syscap SystemCapability.FileManagement.UserFileManager.Core 527 * @returns A Promise instance used to return the file in the format of a T instance. 528 */ 529 getFirstObject(): Promise<T>; 530 /** 531 * Obtains the next T in the file retrieval result. 532 * This method uses a callback to return the file. 533 * Before calling this method, you must use isAfterLast() to check whether the result set points to the last row. 534 * This method returns the next file only when False is returned for isAfterLast(). 535 * @since 9 536 * @systemapi 537 * @syscap SystemCapability.FileManagement.UserFileManager.Core 538 * @param callback Callback used to return the file in the format of a T instance. 539 */ 540 getNextObject(callback: AsyncCallback<T>): void; 541 /** 542 * Obtains the next T in the file retrieval result. 543 * This method uses a promise to return the file. 544 * Before calling this method, you must use isAfterLast() to check whether the result set points to the last row. 545 * This method returns the next file only when False is returned for isAfterLast(). 546 * @since 9 547 * @systemapi 548 * @syscap SystemCapability.FileManagement.UserFileManager.Core 549 * @returns A Promise instance used to return the file in the format of a T instance. 550 */ 551 getNextObject(): Promise<T>; 552 /** 553 * Obtains the last T in the file retrieval result. This method uses a callback to return the file. 554 * @since 9 555 * @systemapi 556 * @syscap SystemCapability.FileManagement.UserFileManager.Core 557 * @param callback Callback used to return the file in the format of a T instance. 558 */ 559 getLastObject(callback: AsyncCallback<T>): void; 560 /** 561 * Obtains the last T in the file retrieval result. This method uses a promise to return the file. 562 * @since 9 563 * @systemapi 564 * @syscap SystemCapability.FileManagement.UserFileManager.Core 565 * @returns A Promise instance used to return the file in the format of a T instance. 566 */ 567 getLastObject(): Promise<T>; 568 /** 569 * Obtains the T with the specified index in the file retrieval result. 570 * This method uses a callback to return the file. 571 * @since 9 572 * @systemapi 573 * @syscap SystemCapability.FileManagement.UserFileManager.Core 574 * @param index Index of the file to obtain. 575 * @param callback Callback used to return the file in the format of a T instance. 576 * @throws {BusinessError} 13900020 - if type index is not number 577 */ 578 getPositionObject(index: number, callback: AsyncCallback<T>): void; 579 /** 580 * Obtains the T with the specified index in the file retrieval result. 581 * This method uses a promise to return the file. 582 * @since 9 583 * @systemapi 584 * @syscap SystemCapability.FileManagement.UserFileManager.Core 585 * @param index Index of the file to obtain. 586 * @throws {BusinessError} 13900020 - if type index is not number 587 * @returns A Promise instance used to return the file in the format of a T instance. 588 */ 589 getPositionObject(index: number): Promise<T>; 590 } 591 592 /** 593 * Defines the AbsAlbum. 594 * @since 9 595 * @systemapi 596 * @syscap SystemCapability.FileManagement.UserFileManager.Core 597 */ 598 interface AbsAlbum { 599 /** 600 * Album name. 601 * @since 9 602 * @systemapi 603 * @syscap SystemCapability.FileManagement.UserFileManager.Core 604 */ 605 albumName: string; 606 /** 607 * Album uri. 608 * @since 9 609 * @systemapi 610 * @syscap SystemCapability.FileManagement.UserFileManager.Core 611 */ 612 readonly albumUri: string; 613 /** 614 * Date (timestamp) when the album was last modified. 615 * @since 9 616 * @systemapi 617 * @syscap SystemCapability.FileManagement.UserFileManager.Core 618 */ 619 readonly dateModified: number; 620 /** 621 * File count for the album 622 * @since 9 623 * @systemapi 624 * @syscap SystemCapability.FileManagement.UserFileManager.Core 625 */ 626 readonly count: number; 627 /** 628 * CoverUri for the album 629 * @since 9 630 * @systemapi 631 * @syscap SystemCapability.FileManagement.UserFileManager.Core 632 */ 633 readonly coverUri: string; 634 /** 635 * Obtains files in an album. This method uses an asynchronous callback to return the files. 636 * @since 9 637 * @systemapi 638 * @syscap SystemCapability.FileManagement.UserFileManager.Core 639 * @permission ohos.permission.READ_IMAGEVIDEO 640 * @param type Determined which kinds of asset to retrive. 641 * @param options Retrieval options. 642 * @param callback Callback used to return the files in the format of a FetchResult instance. 643 * @throws {BusinessError} 13900020 - if type options is not FetchOptions 644 */ 645 getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 646 /** 647 * Obtains files in an album. This method uses a promise to return the files. 648 * @since 9 649 * @systemapi 650 * @syscap SystemCapability.FileManagement.UserFileManager.Core 651 * @permission ohos.permission.READ_IMAGEVIDEO 652 * @param type Determined which kinds of asset to retrive. 653 * @param options Retrieval options. 654 * @throws {BusinessError} 13900020 - if type options is not FetchOptions 655 * @returns A Promise instance used to return the files in the format of a FetchResult instance. 656 */ 657 getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 658 } 659 660 /** 661 * Defines the album. 662 * @since 9 663 * @systemapi 664 * @syscap SystemCapability.FileManagement.UserFileManager.Core 665 */ 666 interface Album extends AbsAlbum { 667 /** 668 * Modify the meta data for the album 669 * @since 9 670 * @systemapi 671 * @syscap SystemCapability.FileManagement.UserFileManager.Core 672 * @permission ohos.permission.WRITE_IMAGEVIDEO 673 * @param callback No value will be returned. 674 */ 675 commitModify(callback: AsyncCallback<void>): void; 676 /** 677 * Modify the meta data for the album 678 * @since 9 679 * @systemapi 680 * @syscap SystemCapability.FileManagement.UserFileManager.Core 681 * @permission ohos.permission.WRITE_IMAGEVIDEO 682 */ 683 commitModify(): Promise<void>; 684 } 685 686 /** 687 * Defines the UserFileManager class and provides functions to access the data in user file storage. 688 * @since 9 689 * @systemapi 690 * @syscap SystemCapability.FileManagement.UserFileManager.Core 691 */ 692 interface UserFileManager { 693 /** 694 * Query photo, video assets 695 * @since 9 696 * @systemapi 697 * @syscap SystemCapability.FileManagement.UserFileManager.Core 698 * @permission ohos.permission.READ_IMAGEVIDEO 699 * @param options retrieval options. 700 * @param callback Callback return the FetchResult. 701 * @throws {BusinessError} 13900020 - if type options is not FetchOptions 702 */ 703 getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 704 /** 705 * Query photo, video assets 706 * @since 9 707 * @systemapi 708 * @syscap SystemCapability.FileManagement.UserFileManager.Core 709 * @permission ohos.permission.READ_IMAGEVIDEO 710 * @param type Determined which kinds of asset to retrive. 711 * @param options Retrieval options. 712 * @throws {BusinessError} 13900020 - if type options is not FetchOptions 713 * @returns A promise instance used to return the files in the format of a FetchResult instance 714 */ 715 getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 716 /** 717 * Create Photo Asset 718 * @since 9 719 * @systemapi 720 * @syscap SystemCapability.FileManagement.UserFileManager.Core 721 * @permission ohos.permission.WRITE_IMAGEVIDEO 722 * @param displayName File name 723 * @param albumUri Asset will put into the album. 724 * @param callback Callback used to return the FileAsset 725 * @throws {BusinessError} 13900020 - if type displayName or albumUri is not string 726 * @throws {BusinessError} 14000001 - if type displayName invalid 727 */ 728 createPhotoAsset(displayName: string, albumUri: string, callback: AsyncCallback<FileAsset>): void; 729 /** 730 * Create Photo Asset 731 * @since 9 732 * @systemapi 733 * @syscap SystemCapability.FileManagement.UserFileManager.Core 734 * @permission ohos.permission.WRITE_IMAGEVIDEO 735 * @param displayName File name 736 * @param callback Callback used to return the FileAsset 737 * @throws {BusinessError} 13900020 - if type displayName is not string 738 * @throws {BusinessError} 14000001 - if type displayName invalid 739 */ 740 createPhotoAsset(displayName: string, callback: AsyncCallback<FileAsset>): void; 741 /** 742 * Create Photo Asset 743 * @since 9 744 * @systemapi 745 * @syscap SystemCapability.FileManagement.UserFileManager.Core 746 * @permission ohos.permission.WRITE_IMAGEVIDEO 747 * @param displayName File name 748 * @param albumUri Album uri is optional, asset will put into the default album without albumUri 749 * @throws {BusinessError} 13900020 - if type displayName or albumUri is not string 750 * @returns A Promise instance used to return the FileAsset 751 */ 752 createPhotoAsset(displayName: string, albumUri?: string): Promise<FileAsset>; 753 /** 754 * Obtains albums based on the retrieval options. This method uses an asynchronous callback to return. 755 * @since 9 756 * @systemapi 757 * @syscap SystemCapability.FileManagement.UserFileManager.Core 758 * @permission ohos.permission.READ_IMAGEVIDEO 759 * @param options Retrieval options. 760 * @param callback Callback used to return an album array. 761 * @throws {BusinessError} 13900020 - if type options is not AlbumFetchOptions 762 */ 763 getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback<FetchResult<Album>>): void; 764 /** 765 * Obtains albums based on the retrieval options. This method uses a promise to return the albums. 766 * @since 9 767 * @systemapi 768 * @syscap SystemCapability.FileManagement.UserFileManager.Core 769 * @permission ohos.permission.READ_IMAGEVIDEO 770 * @param options Retrieval options. 771 * @throws {BusinessError} 13900020 - if type options is not AlbumFetchOptions 772 * @returns A Promise instance used to return an album array. 773 */ 774 getPhotoAlbums(options: AlbumFetchOptions): Promise<FetchResult<Album>>; 775 /** 776 * Obtains system private albums based on the private album type. This method uses an asynchronous callback to return. 777 * @since 9 778 * @systemapi 779 * @syscap SystemCapability.FileManagement.UserFileManager.Core 780 * @permission ohos.permission.READ_IMAGEVIDEO 781 * @param type Private album type 782 * @param callback Used to return a private album FetchResult. 783 * @throws {BusinessError} 13900020 - if type type is not PrivateAlbumType 784 */ 785 getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback<FetchResult<PrivateAlbum>>): void; 786 /** 787 * Obtains system private albums based on the private album type. This method uses a promise to return. 788 * @since 9 789 * @systemapi 790 * @syscap SystemCapability.FileManagement.UserFileManager.Core 791 * @permission ohos.permission.READ_IMAGEVIDEO 792 * @param type Private album type 793 * @throws {BusinessError} 13900020 - if type type is not PrivateAlbumType 794 * @returns A Promise instance used to return a private album FetchResult. 795 */ 796 getPrivateAlbum(type: PrivateAlbumType): Promise<FetchResult<PrivateAlbum>>; 797 /** 798 * Query audio assets 799 * @since 9 800 * @systemapi 801 * @syscap SystemCapability.FileManagement.UserFileManager.Core 802 * @permission ohos.permission.READ_AUDIO 803 * @param options Retrieval options. 804 * @param callback Callback return the FetchResult. 805 * @throws {BusinessError} 13900020 - if type options is not FetchOptions 806 */ 807 getAudioAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 808 /** 809 * Query audio assets 810 * @since 9 811 * @systemapi 812 * @syscap SystemCapability.FileManagement.UserFileManager.Core 813 * @permission ohos.permission.READ_AUDIO 814 * @param type Determined which kinds of asset to retrive. 815 * @param options Retrieval options. 816 * @throws {BusinessError} 13900020 - if type options is not FetchOptions 817 * @returns A promise instance used to return the files in the format of a FetchResult instance 818 */ 819 getAudioAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 820 /** 821 * Delete Asset 822 * @since 9 823 * @systemapi 824 * @syscap SystemCapability.FileManagement.UserFileManager.Core 825 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 826 * @param uri Uri of asset 827 * @param callback No value returned 828 * @throws {BusinessError} 13900020 - if type uri is not string 829 */ 830 delete(uri: string, callback: AsyncCallback<void>): void; 831 /** 832 * Delete Asset 833 * @since 9 834 * @systemapi 835 * @syscap SystemCapability.FileManagement.UserFileManager.Core 836 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 837 * @param uri Uri of asset 838 * @throws {BusinessError} 13900020 - if type uri is not string 839 * @returns A Promise instance, no value returned 840 */ 841 delete(uri: string): Promise<void>; 842 /** 843 * Turn on monitor the data changes 844 * @since 9 845 * @systemapi 846 * @syscap SystemCapability.FileManagement.UserFileManager.Core 847 * @param type One of 'deviceChange','albumChange','imageChange','audioChange','videoChange','remoteFileChange' 848 * @param callback No value returned 849 */ 850 on(type: ChangeEvent, callback: Callback<void>): void; 851 /** 852 * Turn off monitor the data changes 853 * @since 9 854 * @systemapi 855 * @syscap SystemCapability.FileManagement.UserFileManager.Core 856 * @param type One of 'deviceChange','albumChange','imageChange','audioChange','videoChange','remoteFileChange' 857 * @param callback No value returned 858 */ 859 off(type: ChangeEvent, callback?: Callback<void>): void; 860 /** 861 * Get Active Peer device information 862 * @since 9 863 * @systemapi 864 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 865 * @param callback, Callback return the list of the active peer devices' information 866 */ 867 getActivePeers(callback: AsyncCallback<Array<PeerInfo>>): void; 868 /** 869 * Get Active Peer device information 870 * @since 9 871 * @systemapi 872 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 873 * @returns Promise used to return the list of the active peer devices' information 874 */ 875 getActivePeers(): Promise<Array<PeerInfo>>; 876 /** 877 * Get all the peer devices' information 878 * @since 9 879 * @systemapi 880 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 881 * @param callback Callback return the list of the all the peer devices' information 882 */ 883 getAllPeers(callback: AsyncCallback<Array<PeerInfo>>): void; 884 /** 885 * Get all the peer devices' information 886 * @since 9 887 * @systemapi 888 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 889 * @returns Promise used to return the list of the all the peer devices' information 890 */ 891 getAllPeers(): Promise<Array<PeerInfo>>; 892 /** 893 * Release UserFileManager instance 894 * @since 9 895 * @systemapi 896 * @syscap SystemCapability.FileManagement.UserFileManager.Core 897 * @param callback no value returned 898 */ 899 release(callback: AsyncCallback<void>): void; 900 /** 901 * Release UserFileManager instance 902 * @since 9 903 * @systemapi 904 * @syscap SystemCapability.FileManagement.UserFileManager.Core 905 */ 906 release(): Promise<void>; 907 } 908 909 /** 910 * Peer devices' information 911 * @since 9 912 * @systemapi 913 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 914 */ 915 interface PeerInfo { 916 /** 917 * Peer device name 918 * @since 9 919 * @systemapi 920 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 921 */ 922 readonly deviceName: string; 923 /** 924 * Peer device network id 925 * @since 9 926 * @systemapi 927 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 928 */ 929 readonly networkId: string; 930 /** 931 * Peer device online status 932 * @since 9 933 * @systemapi 934 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 935 */ 936 readonly isOnline: boolean; 937 } 938 939 /** 940 * Private album type 941 * @since 9 942 * @systemapi 943 * @syscap SystemCapability.FileManagement.UserFileManager.Core 944 */ 945 enum PrivateAlbumType { 946 /** 947 * System Private Album: Favorite album 948 * @since 9 949 * @systemapi 950 * @syscap SystemCapability.FileManagement.UserFileManager.Core 951 */ 952 TYPE_FAVORITE, 953 /** 954 * System Private Album: Trash album 955 * @since 9 956 * @systemapi 957 * @syscap SystemCapability.FileManagement.UserFileManager.Core 958 */ 959 TYPE_TRASH 960 } 961 962 /** 963 * Defines the private album 964 * @since 9 965 * @systemapi 966 * @syscap SystemCapability.FileManagement.UserFileManager.Core 967 */ 968 interface PrivateAlbum extends AbsAlbum { 969 /** 970 * Delete asset permanently from Trash bin, only support the Trash album 971 * @since 9 972 * @systemapi 973 * @syscap SystemCapability.FileManagement.UserFileManager.Core 974 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 975 * @param uri uri of asset 976 * @param callback No value returned 977 */ 978 delete(uri: string, callback: AsyncCallback<void>): void; 979 /** 980 * Delete asset permanently from Trash bin, only support the Trash album 981 * @since 9 982 * @systemapi 983 * @syscap SystemCapability.FileManagement.UserFileManager.Core 984 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 985 * @param uri Uri of asset 986 * @returns A Promise instance, no value returned 987 */ 988 delete(uri: string): Promise<void>; 989 /** 990 * Recover asset from Trash bin, only support the Trash album 991 * @since 9 992 * @systemapi 993 * @syscap SystemCapability.FileManagement.UserFileManager.Core 994 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 995 * @param uri Uri of asset 996 * @param callback No value returned 997 */ 998 recover(uri: string, callback: AsyncCallback<void>): void; 999 /** 1000 * Recover asset from Trash bin, only support the Trash album 1001 * @since 9 1002 * @systemapi 1003 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1004 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 1005 * @param uri Uri of asset 1006 * @returns A Promise instance, no value returned 1007 */ 1008 recover(uri: string): Promise<void>; 1009 } 1010} 1011 1012export default userFileManager; 1013