1/* 2 * Copyright (C) 2022-2023 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 type { AsyncCallback, Callback } from './@ohos.base'; 17import type Context from './application/Context'; 18import image from './@ohos.multimedia.image'; 19import dataSharePredicates from './@ohos.data.dataSharePredicates'; 20 21/** 22 * @namespace userFileManager 23 * @syscap SystemCapability.FileManagement.UserFileManager.Core 24 * @systemapi 25 * @since 9 26 */ 27declare namespace userFileManager { 28 /** 29 * Returns an instance of UserFileManager 30 * 31 * @param { Context } context - Hap context information 32 * @returns { UserFileManager } Instance of UserFileManager 33 * @syscap SystemCapability.FileManagement.UserFileManager.Core 34 * @systemapi 35 * @StageModelOnly 36 * @since 9 37 */ 38 function getUserFileMgr(context: Context): UserFileManager; 39 40 /** 41 * Enumeration types for different kinds of Files 42 * 43 * @enum { number } FileType 44 * @syscap SystemCapability.FileManagement.UserFileManager.Core 45 * @systemapi 46 * @since 9 47 */ 48 enum FileType { 49 /** 50 * Image file type 51 * 52 * @syscap SystemCapability.FileManagement.UserFileManager.Core 53 * @systemapi 54 * @since 9 55 */ 56 IMAGE = 1, 57 /** 58 * Video file type 59 * 60 * @syscap SystemCapability.FileManagement.UserFileManager.Core 61 * @systemapi 62 * @since 9 63 */ 64 VIDEO, 65 /** 66 * Audio file type 67 * 68 * @syscap SystemCapability.FileManagement.UserFileManager.Core 69 * @systemapi 70 * @since 9 71 */ 72 AUDIO 73 } 74 75 /** 76 * Enumeration types for different types of FileAsset 77 * 78 * @enum { number } PhotoSubType 79 * @syscap SystemCapability.FileManagement.UserFileManager.Core 80 * @systemapi 81 * @since 10 82 */ 83 enum PhotoSubType { 84 /** 85 * Default Photo Type 86 * 87 * @syscap SystemCapability.FileManagement.UserFileManager.Core 88 * @systemapi 89 * @since 10 90 */ 91 DEFAULT, 92 /** 93 * Screenshot Photo Type 94 * 95 * @syscap SystemCapability.FileManagement.UserFileManager.Core 96 * @systemapi 97 * @since 10 98 */ 99 SCREENSHOT, 100 /** 101 * Camera Photo Type 102 * 103 * @syscap SystemCapability.FileManagement.UserFileManager.Core 104 * @systemapi 105 * @since 10 106 */ 107 CAMERA 108 } 109 110 /** 111 * File position 112 * 113 * @enum { number } File position, which indicates the file is on local device or cloud 114 * @syscap SystemCapability.FileManagement.UserFileManager.Core 115 * @systemapi 116 * @since 10 117 */ 118 enum PositionType { 119 /** 120 * File exists only on local device 121 * 122 * @syscap SystemCapability.FileManagement.UserFileManager.Core 123 * @systemapi 124 * @since 10 125 */ 126 LOCAL = 1, 127 /** 128 * File exists only on cloud 129 * 130 * @syscap SystemCapability.FileManagement.UserFileManager.Core 131 * @systemapi 132 * @since 10 133 */ 134 CLOUD, 135 /** 136 * File exists on both local and cloud 137 * 138 * @syscap SystemCapability.FileManagement.UserFileManager.Core 139 * @systemapi 140 * @since 10 141 */ 142 BOTH 143 } 144 145 /** 146 * Indicates the type of file asset member. 147 * 148 * @syscap SystemCapability.FileManagement.UserFileManager.Core 149 * @systemapi 150 * @since 9 151 */ 152 type MemberType = number | string | boolean; 153 154 /** 155 * Indicates the type of notify event. 156 * 157 * @syscap SystemCapability.FileManagement.UserFileManager.Core 158 * @systemapi 159 * @since 9 160 */ 161 type ChangeEvent = 162 'deviceChange' 163 | 'albumChange' 164 | 'imageChange' 165 | 'audioChange' 166 | 'videoChange' 167 | 'remoteFileChange'; 168 169 /** 170 * Provides methods to encapsulate file attributes. 171 * 172 * @interface FileAsset 173 * @syscap SystemCapability.FileManagement.UserFileManager.Core 174 * @systemapi 175 * @since 9 176 */ 177 interface FileAsset { 178 /** 179 * URI of the file. 180 * 181 * @syscap SystemCapability.FileManagement.UserFileManager.Core 182 * @systemapi 183 * @since 9 184 */ 185 readonly uri: string; 186 /** 187 * File type, for example, IMAGE, VIDEO, AUDIO 188 * 189 * @syscap SystemCapability.FileManagement.UserFileManager.Core 190 * @systemapi 191 * @since 9 192 */ 193 readonly fileType: FileType; 194 /** 195 * Display name (with a file name extension) of the file. 196 * 197 * @syscap SystemCapability.FileManagement.UserFileManager.Core 198 * @systemapi 199 * @since 9 200 */ 201 displayName: string; 202 /** 203 * Return the fileAsset member parameter. 204 * 205 * @param { string } member - The name of the parameter. for example : get(ImageVideoKey.URI) 206 * @returns { MemberType } 207 * @syscap SystemCapability.FileManagement.UserFileManager.Core 208 * @systemapi 209 * @since 9 210 */ 211 get(member: string): MemberType; 212 /** 213 * Set the fileAsset member parameter. 214 * 215 * @param { string } member - The name of the parameter 216 * @param { string } value - The value of the parameter. 217 * @syscap SystemCapability.FileManagement.UserFileManager.Core 218 * @systemapi 219 * @since 9 220 * @example : Set(ImageVideoKey.TITLE, "newTitle"), call commitModify after set value 221 */ 222 set(member: string, value: string): void; 223 /** 224 * Modify meta data where the file is located. 225 * 226 * @permission ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 227 * @param { AsyncCallback<void> } callback - No value will be returned. 228 * @syscap SystemCapability.FileManagement.UserFileManager.Core 229 * @systemapi 230 * @since 9 231 */ 232 commitModify(callback: AsyncCallback<void>): void; 233 /** 234 * Modify meta data where the file is located. 235 * 236 * @permission ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 237 * @returns { Promise<void> } Return promise 238 * @syscap SystemCapability.FileManagement.UserFileManager.Core 239 * @systemapi 240 * @since 9 241 */ 242 commitModify(): Promise<void>; 243 /** 244 * Open local file. 245 * 246 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO or ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 247 * @param { string } mode - Mode for open, for example: rw, r, w. 248 * @param { AsyncCallback<number> } callback - Callback return the fd of the file. 249 * @syscap SystemCapability.FileManagement.UserFileManager.Core 250 * @systemapi 251 * @since 9 252 */ 253 open(mode: string, callback: AsyncCallback<number>): void; 254 /** 255 * Open local file. 256 * 257 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO or ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 258 * @param { string } mode - Mode for open, for example: rw, r, w. 259 * @returns { Promise<number> } Return promise 260 * @syscap SystemCapability.FileManagement.UserFileManager.Core 261 * @systemapi 262 * @since 9 263 */ 264 open(mode: string): Promise<number>; 265 /** 266 * Close the file is located. 267 * 268 * @param { number } fd - Fd of the file which had been opened 269 * @param { AsyncCallback<void> } callback - No value will be returned. 270 * @syscap SystemCapability.FileManagement.UserFileManager.Core 271 * @systemapi 272 * @since 9 273 */ 274 close(fd: number, callback: AsyncCallback<void>): void; 275 /** 276 * Close the file is located. 277 * 278 * @param { number } fd - Fd of the file which had been opened 279 * @returns { Promise<void> } Return promise 280 * @syscap SystemCapability.FileManagement.UserFileManager.Core 281 * @systemapi 282 * @since 9 283 */ 284 close(fd: number): Promise<void>; 285 /** 286 * Get thumbnail of the file when the file is located. 287 * 288 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 289 * @param { AsyncCallback<image.PixelMap> } callback - Callback used to return the thumbnail's pixelMap. 290 * @syscap SystemCapability.FileManagement.UserFileManager.Core 291 * @systemapi 292 * @since 9 293 */ 294 getThumbnail(callback: AsyncCallback<image.PixelMap>): void; 295 /** 296 * Get thumbnail of the file when the file is located. 297 * 298 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 299 * @param { image.Size } size - Thumbnail's size 300 * @param { AsyncCallback<image.PixelMap> } callback - Callback used to return the thumbnail's pixelMap. 301 * @syscap SystemCapability.FileManagement.UserFileManager.Core 302 * @systemapi 303 * @since 9 304 */ 305 getThumbnail(size: image.Size, callback: AsyncCallback<image.PixelMap>): void; 306 /** 307 * Get thumbnail of the file when the file is located. 308 * 309 * @permission ohos.permission.READ_IMAGEVIDEO or ohos.permission.READ_AUDIO 310 * @param { image.Size } size - Thumbnail's size 311 * @returns { Promise<image.PixelMap> } Return promise 312 * @syscap SystemCapability.FileManagement.UserFileManager.Core 313 * @systemapi 314 * @since 9 315 */ 316 getThumbnail(size?: image.Size): Promise<image.PixelMap>; 317 /** 318 * Set favorite for the file when the file is located. 319 * 320 * @permission ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 321 * @param { boolean } isFavorite - True is favorite file, false is not favorite file 322 * @param { AsyncCallback<void> } callback - Callback used to return, No value is returned. 323 * @syscap SystemCapability.FileManagement.UserFileManager.Core 324 * @systemapi 325 * @since 9 326 */ 327 favorite(isFavorite: boolean, callback: AsyncCallback<void>): void; 328 /** 329 * Set favorite for the file when the file is located. 330 * 331 * @permission ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.WRITE_AUDIO 332 * @param { boolean } isFavorite - isFavorite True is favorite file, false is not favorite file 333 * @returns { Promise<void> } Return promise 334 * @syscap SystemCapability.FileManagement.UserFileManager.Core 335 * @systemapi 336 * @since 9 337 */ 338 favorite(isFavorite: boolean): Promise<void>; 339 /** 340 * Set file hidden state. 341 * 342 * @permission ohos.permission.WRITE_IMAGEVIDEO 343 * @param { boolean } hiddenState - true: Put the asset into hidden album; false: Recover the asset from hidden album. 344 * @param { AsyncCallback<void> } callback - Return void. 345 * @throws { BusinessError } 202 - Called by non-system application. 346 * @throws { BusinessError } 13900020 - if parameter is invalid 347 * @syscap SystemCapability.FileManagement.UserFileManager.Core 348 * @systemapi 349 * @since 10 350 */ 351 setHidden(hiddenState: boolean, callback: AsyncCallback<void>): void; 352 /** 353 * Set file hidden state. 354 * 355 * @permission ohos.permission.WRITE_IMAGEVIDEO 356 * @param { boolean } hiddenState - true: Put the asset into hidden album; false: Recover the asset from hidden album. 357 * @returns { Promise<void> } Returns the promise 358 * @throws { BusinessError } 202 - Called by non-system application. 359 * @throws { BusinessError } 13900020 - if parameter is invalid 360 * @syscap SystemCapability.FileManagement.UserFileManager.Core 361 * @systemapi 362 * @since 10 363 */ 364 setHidden(hiddenState: boolean): Promise<void>; 365 /** 366 * Set user comment info to the asset. 367 * 368 * @permission ohos.permission.WRITE_IMAGEVIDEO 369 * @param { string } userComment - user comment info 370 * @param { AsyncCallback<void> } callback - Returns void. 371 * @throws { BusinessError } 202 - Called by non-system application. 372 * @throws { BusinessError } 401 - if parameter is invalid 373 * @syscap SystemCapability.FileManagement.UserFileManager.Core 374 * @systemapi 375 * @since 10 376 */ 377 setUserComment(userComment: string, callback: AsyncCallback<void>): void; 378 /** 379 * Set user comment info to the asset. 380 * 381 * @permission ohos.permission.WRITE_IMAGEVIDEO 382 * @param { string } userComment - user comment info 383 * @returns { Promise<void> } Returns void 384 * @throws { BusinessError } 202 - Called by non-system application. 385 * @throws { BusinessError } 401 - if parameter is invalid 386 * @syscap SystemCapability.FileManagement.UserFileManager.Core 387 * @systemapi 388 * @since 10 389 */ 390 setUserComment(userComment: string): Promise<void>; 391 /** 392 * Get exif info of the asset. 393 * 394 * @permission ohos.permission.READ_IMAGEVIDEO 395 * @param { AsyncCallback<string> } callback - Returns exif info into a json string 396 * @throws { BusinessError } 202 - Called by non-system application. 397 * @syscap SystemCapability.FileManagement.UserFileManager.Core 398 * @systemapi 399 * @since 10 400 */ 401 getExif(callback: AsyncCallback<string>): void; 402 /** 403 * Get exif info of the asset. 404 * 405 * @permission ohos.permission.READ_IMAGEVIDEO 406 * @returns { Promise<string> } Returns exif info into a json string 407 * @throws { BusinessError } 202 - Called by non-system application. 408 * @syscap SystemCapability.FileManagement.UserFileManager.Core 409 * @systemapi 410 * @since 10 411 */ 412 getExif(): Promise<string>; 413 } 414 415 /** 416 * Describes AUDIO TYPE FetchOptions's predicate 417 * 418 * @enum { string } AudioKey 419 * @syscap SystemCapability.FileManagement.UserFileManager.Core 420 * @systemapi 421 * @since 9 422 */ 423 enum AudioKey { 424 /** 425 * File uri, read only 426 * 427 * @syscap SystemCapability.FileManagement.UserFileManager.Core 428 * @systemapi 429 * @since 9 430 */ 431 URI, 432 /** 433 * File name 434 * 435 * @syscap SystemCapability.FileManagement.UserFileManager.Core 436 * @systemapi 437 * @since 9 438 */ 439 DISPLAY_NAME, 440 /** 441 * Date of the file creation, read only 442 * 443 * @syscap SystemCapability.FileManagement.UserFileManager.Core 444 * @systemapi 445 * @since 9 446 */ 447 DATE_ADDED, 448 /** 449 * Modify date of the file, read only 450 * 451 * @syscap SystemCapability.FileManagement.UserFileManager.Core 452 * @systemapi 453 * @since 9 454 */ 455 DATE_MODIFIED, 456 /** 457 * Title of the file, read only 458 * 459 * @syscap SystemCapability.FileManagement.UserFileManager.Core 460 * @systemapi 461 * @since 9 462 */ 463 TITLE, 464 /** 465 * Artist of the audio file, read only 466 * 467 * @syscap SystemCapability.FileManagement.UserFileManager.Core 468 * @systemapi 469 * @since 9 470 */ 471 ARTIST, 472 /** 473 * Audio album of the audio file, read only 474 * 475 * @syscap SystemCapability.FileManagement.UserFileManager.Core 476 * @systemapi 477 * @since 9 478 */ 479 AUDIOALBUM, 480 /** 481 * Duration of the audio file, read only 482 * 483 * @syscap SystemCapability.FileManagement.UserFileManager.Core 484 * @systemapi 485 * @since 9 486 */ 487 DURATION, 488 /** 489 * Favorite state of the file, read only 490 * 491 * @syscap SystemCapability.FileManagement.UserFileManager.Core 492 * @systemapi 493 * @since 9 494 */ 495 FAVORITE 496 } 497 498 /** 499 * Describes Image, Video TYPE FetchOptions's predicate 500 * 501 * @enum { string } ImageVideoKey 502 * @syscap SystemCapability.FileManagement.UserFileManager.Core 503 * @systemapi 504 * @since 9 505 */ 506 enum ImageVideoKey { 507 /** 508 * File uri, read only 509 * 510 * @syscap SystemCapability.FileManagement.UserFileManager.Core 511 * @systemapi 512 * @since 9 513 */ 514 URI, 515 /** 516 * File type of the Asset, read only 517 * 518 * @syscap SystemCapability.FileManagement.UserFileManager.Core 519 * @systemapi 520 * @since 9 521 */ 522 FILE_TYPE, 523 /** 524 * File name 525 * 526 * @syscap SystemCapability.FileManagement.UserFileManager.Core 527 * @systemapi 528 * @since 9 529 */ 530 DISPLAY_NAME, 531 /** 532 * Date of the file creation, read only 533 * 534 * @syscap SystemCapability.FileManagement.UserFileManager.Core 535 * @systemapi 536 * @since 9 537 */ 538 DATE_ADDED, 539 /** 540 * Modify date of the file, read only 541 * 542 * @syscap SystemCapability.FileManagement.UserFileManager.Core 543 * @systemapi 544 * @since 9 545 */ 546 DATE_MODIFIED, 547 /** 548 * Title of the file, read only 549 * 550 * @syscap SystemCapability.FileManagement.UserFileManager.Core 551 * @systemapi 552 * @since 9 553 */ 554 TITLE, 555 /** 556 * Duration of the audio and video file, read only 557 * 558 * @syscap SystemCapability.FileManagement.UserFileManager.Core 559 * @systemapi 560 * @since 9 561 */ 562 DURATION, 563 /** 564 * Width of the image file, read only 565 * 566 * @syscap SystemCapability.FileManagement.UserFileManager.Core 567 * @systemapi 568 * @since 9 569 */ 570 WIDTH, 571 /** 572 * Height of the image file, read only 573 * 574 * @syscap SystemCapability.FileManagement.UserFileManager.Core 575 * @systemapi 576 * @since 9 577 */ 578 HEIGHT, 579 /** 580 * Date taken of the file, read only 581 * 582 * @syscap SystemCapability.FileManagement.UserFileManager.Core 583 * @systemapi 584 * @since 9 585 */ 586 DATE_TAKEN, 587 /** 588 * Orientation of the image file, read only 589 * 590 * @syscap SystemCapability.FileManagement.UserFileManager.Core 591 * @systemapi 592 * @since 9 593 */ 594 ORIENTATION, 595 /** 596 * Favorite state of the file, read only 597 * 598 * @syscap SystemCapability.FileManagement.UserFileManager.Core 599 * @systemapi 600 * @since 9 601 */ 602 FAVORITE, 603 /** 604 * File position, read only 605 * 606 * @syscap SystemCapability.FileManagement.UserFileManager.Core 607 * @systemapi 608 * @since 10 609 */ 610 POSITION, 611 /** 612 * Trashed date of the file, read only 613 * 614 * @syscap SystemCapability.FileManagement.UserFileManager.Core 615 * @systemapi 616 * @since 10 617 */ 618 DATE_TRASHED, 619 /** 620 * Hidden state of the file, read only 621 * 622 * @syscap SystemCapability.FileManagement.UserFileManager.Core 623 * @systemapi 624 * @since 10 625 */ 626 HIDDEN, 627 /** 628 * User comment info 629 * 630 * @syscap SystemCapability.FileManagement.UserFileManager.Core 631 * @systemapi 632 * @since 10 633 */ 634 USER_COMMENT, 635 /** 636 * Camera shot key 637 * 638 * @syscap SystemCapability.FileManagement.UserFileManager.Core 639 * @systemapi 640 * @since 10 641 */ 642 CAMERA_SHOT_KEY 643 } 644 645 /** 646 * Describes Album TYPE predicate 647 * 648 * @enum { string } AlbumKey 649 * @syscap SystemCapability.FileManagement.UserFileManager.Core 650 * @systemapi 651 * @since 9 652 */ 653 enum AlbumKey { 654 /** 655 * Album uri 656 * 657 * @syscap SystemCapability.FileManagement.UserFileManager.Core 658 * @systemapi 659 * @since 9 660 */ 661 URI, 662 /** 663 * File type of the Album 664 * 665 * @syscap SystemCapability.FileManagement.UserFileManager.Core 666 * @systemapi 667 * @since 9 668 */ 669 FILE_TYPE, 670 /** 671 * Album name 672 * 673 * @syscap SystemCapability.FileManagement.UserFileManager.Core 674 * @systemapi 675 * @since 9 676 */ 677 ALBUM_NAME, 678 /** 679 * Date of the Album creation 680 * 681 * @syscap SystemCapability.FileManagement.UserFileManager.Core 682 * @systemapi 683 * @since 9 684 */ 685 DATE_ADDED, 686 /** 687 * Modify date of the Album 688 * 689 * @syscap SystemCapability.FileManagement.UserFileManager.Core 690 * @systemapi 691 * @since 9 692 */ 693 DATE_MODIFIED 694 } 695 696 /** 697 * Fetch parameters 698 * 699 * @interface FetchOptions 700 * @syscap SystemCapability.FileManagement.UserFileManager.Core 701 * @systemapi 702 * @since 9 703 */ 704 interface FetchOptions { 705 /** 706 * Indicates the columns to query. 707 * 708 * @syscap SystemCapability.FileManagement.UserFileManager.Core 709 * @systemapi 710 * @since 9 711 */ 712 fetchColumns: Array<string>; 713 /** 714 * Predicate to query 715 * 716 * @syscap SystemCapability.FileManagement.UserFileManager.Core 717 * @systemapi 718 * @since 9 719 */ 720 predicates: dataSharePredicates.DataSharePredicates; 721 } 722 723 /** 724 * Fetch parameters 725 * 726 * @interface AlbumFetchOptions 727 * @syscap SystemCapability.FileManagement.UserFileManager.Core 728 * @systemapi 729 * @since 9 730 */ 731 interface AlbumFetchOptions { 732 /** 733 * Predicate to query 734 * 735 * @syscap SystemCapability.FileManagement.UserFileManager.Core 736 * @systemapi 737 * @since 9 738 */ 739 predicates: dataSharePredicates.DataSharePredicates; 740 } 741 742 /** 743 * Describe additional operations for creating photo 744 * 745 * @interface PhotoCreateOptions 746 * @syscap SystemCapability.FileManagement.UserFileManager.Core 747 * @systemapi 748 * @since 10 749 */ 750 interface PhotoCreateOptions { 751 /** 752 * SubType of the photo 753 * 754 * @syscap SystemCapability.FileManagement.UserFileManager.Core 755 * @systemapi 756 * @since 10 757 */ 758 subType?: PhotoSubType; 759 /** 760 * Camera shot key 761 * 762 * @type { ?string } 763 * @syscap SystemCapability.FileManagement.UserFileManager.Core 764 * @systemapi 765 * @since 10 766 */ 767 cameraShotKey?: string; 768 } 769 770 /** 771 * Implements file retrieval. 772 * 773 * @interface FetchResult 774 * @syscap SystemCapability.FileManagement.UserFileManager.Core 775 * @systemapi 776 * @since 9 777 */ 778 interface FetchResult<T> { 779 /** 780 * Obtains the total number of files in the file retrieval result. 781 * 782 * @returns { number } Total number of files. 783 * @syscap SystemCapability.FileManagement.UserFileManager.Core 784 * @systemapi 785 * @since 9 786 */ 787 getCount(): number; 788 /** 789 * Checks whether the result set points to the last row. 790 * 791 * @returns { boolean } Whether the file is the last one. 792 * You need to check whether the file is the last one before calling getNextObject, 793 * which returns the next file only when False is returned for this method. 794 * @syscap SystemCapability.FileManagement.UserFileManager.Core 795 * @systemapi 796 * @since 9 797 */ 798 isAfterLast(): boolean; 799 /** 800 * Releases the FetchResult instance and invalidates it. Other methods cannot be called. 801 * 802 * @syscap SystemCapability.FileManagement.UserFileManager.Core 803 * @systemapi 804 * @since 9 805 */ 806 close(): void; 807 /** 808 * Obtains the first FileAsset in the file retrieval result. This method uses a callback to return the file. 809 * 810 * @param { AsyncCallback<T> } callback - Callback used to return the file in the format of a FileAsset instance. 811 * @syscap SystemCapability.FileManagement.UserFileManager.Core 812 * @systemapi 813 * @since 9 814 */ 815 getFirstObject(callback: AsyncCallback<T>): void; 816 /** 817 * Obtains the first T in the file retrieval result. This method uses a promise to return the file. 818 * 819 * @returns { Promise<T> } A Promise instance used to return the file in the format of a T instance. 820 * @syscap SystemCapability.FileManagement.UserFileManager.Core 821 * @systemapi 822 * @since 9 823 */ 824 getFirstObject(): Promise<T>; 825 /** 826 * Obtains the next T in the file retrieval result. 827 * This method uses a callback to return the file. 828 * Before calling this method, you must use isAfterLast() to check whether the result set points to the last row. 829 * This method returns the next file only when False is returned for isAfterLast(). 830 * 831 * @param { AsyncCallback<T> } callback - Callback used to return the file in the format of a T instance. 832 * @syscap SystemCapability.FileManagement.UserFileManager.Core 833 * @systemapi 834 * @since 9 835 */ 836 getNextObject(callback: AsyncCallback<T>): void; 837 /** 838 * Obtains the next T in the file retrieval result. 839 * This method uses a promise to return the file. 840 * Before calling this method, you must use isAfterLast() to check whether the result set points to the last row. 841 * This method returns the next file only when False is returned for isAfterLast(). 842 * 843 * @returns { Promise<T> } A Promise instance used to return the file in the format of a T instance. 844 * @syscap SystemCapability.FileManagement.UserFileManager.Core 845 * @systemapi 846 * @since 9 847 */ 848 getNextObject(): Promise<T>; 849 /** 850 * Obtains the last T in the file retrieval result. This method uses a callback to return the file. 851 * 852 * @param { AsyncCallback<T> } callback - Callback used to return the file in the format of a T instance. 853 * @syscap SystemCapability.FileManagement.UserFileManager.Core 854 * @systemapi 855 * @since 9 856 */ 857 getLastObject(callback: AsyncCallback<T>): void; 858 /** 859 * Obtains the last T in the file retrieval result. This method uses a promise to return the file. 860 * 861 * @returns { Promise<T> } A Promise instance used to return the file in the format of a T instance. 862 * @syscap SystemCapability.FileManagement.UserFileManager.Core 863 * @systemapi 864 * @since 9 865 */ 866 getLastObject(): Promise<T>; 867 /** 868 * Obtains the T with the specified index in the file retrieval result. 869 * This method uses a callback to return the file. 870 * 871 * @param { number } index - Index of the file to obtain. 872 * @param { AsyncCallback<T> } callback - Callback used to return the file in the format of a T instance. 873 * @throws { BusinessError } 13900020 - if type index is not number 874 * @syscap SystemCapability.FileManagement.UserFileManager.Core 875 * @systemapi 876 * @since 9 877 */ 878 getPositionObject(index: number, callback: AsyncCallback<T>): void; 879 /** 880 * Obtains the T with the specified index in the file retrieval result. 881 * This method uses a promise to return the file. 882 * 883 * @param { number } index - Index of the file to obtain. 884 * @returns { Promise<T> } A Promise instance used to return the file in the format of a T instance. 885 * @throws { BusinessError } 13900020 - if type index is not number 886 * @syscap SystemCapability.FileManagement.UserFileManager.Core 887 * @systemapi 888 * @since 9 889 */ 890 getPositionObject(index: number): Promise<T>; 891 /** 892 * Obtains all T in the file retrieval result. 893 * This method uses a callback to return the result. After this method is called, 894 * 895 * @param { AsyncCallback<Array<T>> } callback - Callback used to return a T array. 896 * @syscap SystemCapability.FileManagement.UserFileManager.Core 897 * @systemapi 898 * @since 10 899 */ 900 getAllObject(callback: AsyncCallback<Array<T>>): void; 901 /** 902 * Obtains all T in the file retrieval result. 903 * This method uses a promise to return the result. that store the selected media resources. 904 * 905 * @returns { Promise<Array<T>> } A Promise instance used to return a T array. 906 * @syscap SystemCapability.FileManagement.UserFileManager.Core 907 * @systemapi 908 * @since 10 909 */ 910 getAllObject(): Promise<Array<T>>; 911 } 912 913 /** 914 * Album type. 915 * 916 * @enum { number } AlbumType 917 * @syscap SystemCapability.FileManagement.UserFileManager.Core 918 * @systemapi 919 * @since 10 920 */ 921 enum AlbumType { 922 /** 923 * Album created by user. 924 * 925 * @syscap SystemCapability.FileManagement.UserFileManager.Core 926 * @systemapi 927 * @since 10 928 */ 929 USER = 0, 930 /** 931 * Album created by system, which metadata cannot be modified by user. 932 * 933 * @syscap SystemCapability.FileManagement.UserFileManager.Core 934 * @systemapi 935 * @since 10 936 */ 937 SYSTEM = 1024 938 } 939 940 /** 941 * Album subtype 942 * 943 * @enum { number } AlbumSubType 944 * @syscap SystemCapability.FileManagement.UserFileManager.Core 945 * @systemapi 946 * @since 10 947 */ 948 enum AlbumSubType { 949 /** 950 * Generic user-created albums. 951 * 952 * @syscap SystemCapability.FileManagement.UserFileManager.Core 953 * @systemapi 954 * @since 10 955 */ 956 USER_GENERIC = 1, 957 /** 958 * Favorite album, which assets are marked as favorite. 959 * 960 * @syscap SystemCapability.FileManagement.UserFileManager.Core 961 * @systemapi 962 * @since 10 963 */ 964 FAVORITE = 1025, 965 /** 966 * Video album, which contains all video assets. 967 * 968 * @syscap SystemCapability.FileManagement.UserFileManager.Core 969 * @systemapi 970 * @since 10 971 */ 972 VIDEO, 973 /** 974 * Hidden album, which assets are marked as hidden. 975 * 976 * @syscap SystemCapability.FileManagement.UserFileManager.Core 977 * @systemapi 978 * @since 10 979 */ 980 HIDDEN, 981 /** 982 * Trash album, which assets are deleted. 983 * 984 * @syscap SystemCapability.FileManagement.UserFileManager.Core 985 * @systemapi 986 * @since 10 987 */ 988 TRASH, 989 /** 990 * Screenshot album 991 * 992 * @syscap SystemCapability.FileManagement.UserFileManager.Core 993 * @systemapi 994 * @since 10 995 */ 996 SCREENSHOT, 997 /** 998 * Camera album 999 * 1000 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1001 * @systemapi 1002 * @since 10 1003 */ 1004 CAMERA, 1005 /** 1006 * Any album 1007 * 1008 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1009 * @systemapi 1010 * @since 10 1011 */ 1012 ANY = 2147483647 1013 } 1014 1015 /** 1016 * Defines the AbsAlbum. 1017 * 1018 * @interface AbsAlbum 1019 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1020 * @systemapi 1021 * @since 9 1022 */ 1023 interface AbsAlbum { 1024 /** 1025 * Album type 1026 * 1027 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1028 * @systemapi 1029 * @since 10 1030 */ 1031 readonly albumType: AlbumType; 1032 /** 1033 * Album subtype 1034 * 1035 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1036 * @systemapi 1037 * @since 10 1038 */ 1039 readonly albumSubType: AlbumSubType; 1040 /** 1041 * Album name. 1042 * 1043 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1044 * @systemapi 1045 * @since 9 1046 */ 1047 albumName: string; 1048 /** 1049 * Album uri. 1050 * 1051 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1052 * @systemapi 1053 * @since 9 1054 */ 1055 readonly albumUri: string; 1056 /** 1057 * Date (timestamp) when the album was last modified. 1058 * 1059 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1060 * @systemapi 1061 * @since 9 1062 */ 1063 readonly dateModified: number; 1064 /** 1065 * File count for the album 1066 * 1067 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1068 * @systemapi 1069 * @since 9 1070 */ 1071 readonly count: number; 1072 /** 1073 * CoverUri for the album 1074 * 1075 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1076 * @systemapi 1077 * @since 9 1078 */ 1079 coverUri: string; 1080 /** 1081 * Obtains files in an album. This method uses an asynchronous callback to return the files. 1082 * 1083 * @permission ohos.permission.READ_IMAGEVIDEO 1084 * @param { FetchOptions } options - Retrieval options. 1085 * @param { AsyncCallback<FetchResult<FileAsset>> } callback - Callback used to return the files in the format of a FetchResult instance. 1086 * @throws { BusinessError } 13900020 - if type options is not FetchOptions 1087 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1088 * @systemapi 1089 * @since 9 1090 */ 1091 getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 1092 /** 1093 * Obtains files in an album. This method uses a promise to return the files. 1094 * 1095 * @permission ohos.permission.READ_IMAGEVIDEO 1096 * @param { FetchOptions } options - Retrieval options. 1097 * @returns { Promise<FetchResult<FileAsset>> } A Promise instance used to return the files in the format of a FetchResult instance. 1098 * @throws { BusinessError } 13900020 - if type options is not FetchOptions 1099 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1100 * @systemapi 1101 * @since 9 1102 */ 1103 getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 1104 } 1105 1106 /** 1107 * Defines the album. 1108 * 1109 * @interface Album 1110 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1111 * @systemapi 1112 * @since 9 1113 */ 1114 interface Album extends AbsAlbum { 1115 /** 1116 * Modify the meta data for the album 1117 * 1118 * @permission ohos.permission.WRITE_IMAGEVIDEO 1119 * @param { AsyncCallback<void> } callback - No value will be returned. 1120 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1121 * @systemapi 1122 * @since 9 1123 */ 1124 commitModify(callback: AsyncCallback<void>): void; 1125 /** 1126 * Modify the meta data for the album 1127 * 1128 * @permission ohos.permission.WRITE_IMAGEVIDEO 1129 * @returns { Promise<void> } Return promise 1130 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1131 * @systemapi 1132 * @since 9 1133 */ 1134 commitModify(): Promise<void>; 1135 /** 1136 * Add PhotoAssets to the album. 1137 * 1138 * @permission ohos.permission.WRITE_IMAGEVIDEO 1139 * @param { Array<FileAsset> } assets - Assets to add 1140 * @param { AsyncCallback<void> } callback - Returns void 1141 * @throws { BusinessError } 13900020 - if PhotoAssets is invalid 1142 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1143 * @systemapi 1144 * @since 10 1145 */ 1146 addPhotoAssets(assets: Array<FileAsset>, callback: AsyncCallback<void>): void; 1147 /** 1148 * Add PhotoAssets to the album. 1149 * 1150 * @permission ohos.permission.WRITE_IMAGEVIDEO 1151 * @param { Array<FileAsset> } assets - Assets to add 1152 * @returns { Promise<void> } Returns the promise 1153 * @throws { BusinessError } 13900020 - if PhotoAssets is invalid 1154 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1155 * @systemapi 1156 * @since 10 1157 */ 1158 addPhotoAssets(assets: Array<FileAsset>): Promise<void>; 1159 /** 1160 * Remove PhotoAssets from the album. 1161 * 1162 * @permission ohos.permission.WRITE_IMAGEVIDEO 1163 * @param { Array<FileAsset> } assets - Assets to remove 1164 * @param { AsyncCallback<void> } callback - Returns void 1165 * @throws { BusinessError } 13900020 - if PhotoAssets is invalid 1166 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1167 * @systemapi 1168 * @since 10 1169 */ 1170 removePhotoAssets(assets: Array<FileAsset>, callback: AsyncCallback<void>): void; 1171 /** 1172 * Remove PhotoAssets from the album. 1173 * 1174 * @permission ohos.permission.WRITE_IMAGEVIDEO 1175 * @param { Array<FileAsset> } assets - Assets to remove 1176 * @returns { Promise<void> } Returns the promise 1177 * @throws { BusinessError } 13900020 - if PhotoAssets is invalid 1178 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1179 * @systemapi 1180 * @since 10 1181 */ 1182 removePhotoAssets(assets: Array<FileAsset>): Promise<void>; 1183 /** 1184 * Recover PhotoAssets from the trash album. 1185 * 1186 * @permission ohos.permission.WRITE_IMAGEVIDEO 1187 * @param { Array<FileAsset> } assets - Assets to recover 1188 * @param { AsyncCallback<void> } callback - Returns void 1189 * @throws { BusinessError } 13900020 - if PhotoAssets is invalid 1190 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1191 * @systemapi 1192 * @since 10 1193 */ 1194 recoverPhotoAssets(assets: Array<FileAsset>, callback: AsyncCallback<void>): void; 1195 /** 1196 * Recover PhotoAssets from the trash album. 1197 * 1198 * @permission ohos.permission.WRITE_IMAGEVIDEO 1199 * @param { Array<FileAsset> } assets - Assets to recover 1200 * @returns { Promise<void> } Returns the promise 1201 * @throws { BusinessError } 13900020 - if PhotoAssets is invalid 1202 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1203 * @systemapi 1204 * @since 10 1205 */ 1206 recoverPhotoAssets(assets: Array<FileAsset>): Promise<void>; 1207 /** 1208 * Delete PhotoAssets permanently from the trash album. 1209 * 1210 * @permission ohos.permission.WRITE_IMAGEVIDEO 1211 * @param { Array<FileAsset> } assets - Assets to delete 1212 * @param { AsyncCallback<void> } callback - Returns void 1213 * @throws { BusinessError } 13900020 - if PhotoAssets is invalid 1214 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1215 * @systemapi 1216 * @since 10 1217 */ 1218 deletePhotoAssets(assets: Array<FileAsset>, callback: AsyncCallback<void>): void; 1219 /** 1220 * Delete PhotoAssets permanently from the trash album. 1221 * 1222 * @permission ohos.permission.WRITE_IMAGEVIDEO 1223 * @param { Array<FileAsset> } assets - Assets to delete 1224 * @returns { Promise<void> } Returns the promise 1225 * @throws { BusinessError } 13900020 - if PhotoAssets is invalid 1226 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1227 * @systemapi 1228 * @since 10 1229 */ 1230 deletePhotoAssets(assets: Array<FileAsset>): Promise<void>; 1231 } 1232 1233 /** 1234 * Defines the UserFileManager class and provides functions to access the data in user file storage. 1235 * 1236 * @interface UserFileManager 1237 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1238 * @systemapi 1239 * @since 9 1240 */ 1241 interface UserFileManager { 1242 /** 1243 * Query photo, video assets 1244 * 1245 * @permission ohos.permission.READ_IMAGEVIDEO 1246 * @param { FetchOptions } options - retrieval options. 1247 * @param { AsyncCallback<FetchResult<FileAsset>> } callback - Callback return the FetchResult. 1248 * @throws { BusinessError } 13900020 - if type options is not FetchOptions 1249 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1250 * @systemapi 1251 * @since 9 1252 */ 1253 getPhotoAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 1254 /** 1255 * Query photo, video assets 1256 * 1257 * @permission ohos.permission.READ_IMAGEVIDEO 1258 * @param { FetchOptions } options - Retrieval options. 1259 * @returns { Promise<FetchResult<FileAsset>> } A promise instance used to return the files in the format of a FetchResult instance 1260 * @throws { BusinessError } 13900020 - if type options is not FetchOptions 1261 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1262 * @systemapi 1263 * @since 9 1264 */ 1265 getPhotoAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 1266 /** 1267 * Create Photo Asset 1268 * 1269 * @permission ohos.permission.WRITE_IMAGEVIDEO 1270 * @param { string } displayName - File name 1271 * @param { string } albumUri - Asset will put into the album. 1272 * @param { AsyncCallback<FileAsset> } callback - Callback used to return the FileAsset 1273 * @throws { BusinessError } 13900020 - if type displayName or albumUri is not string 1274 * @throws { BusinessError } 14000001 - if type displayName invalid 1275 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1276 * @systemapi 1277 * @since 9 1278 */ 1279 createPhotoAsset(displayName: string, albumUri: string, callback: AsyncCallback<FileAsset>): void; 1280 /** 1281 * Create Photo Asset 1282 * 1283 * @permission ohos.permission.WRITE_IMAGEVIDEO 1284 * @param { string } displayName - File name 1285 * @param { AsyncCallback<FileAsset> } callback - Callback used to return the FileAsset 1286 * @throws { BusinessError } 13900020 - if type displayName is not string 1287 * @throws { BusinessError } 14000001 - if type displayName invalid 1288 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1289 * @systemapi 1290 * @since 9 1291 */ 1292 createPhotoAsset(displayName: string, callback: AsyncCallback<FileAsset>): void; 1293 /** 1294 * Create Photo Asset 1295 * 1296 * @permission ohos.permission.WRITE_IMAGEVIDEO 1297 * @param { string } displayName - File name 1298 * @param { string } albumUri - Album uri is optional, PhotoAssets will put into the default album without albumUri 1299 * @returns { Promise<FileAsset> } A Promise instance used to return the FileAsset 1300 * @throws { BusinessError } 13900020 - if type displayName or albumUri is not string 1301 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1302 * @systemapi 1303 * @since 9 1304 */ 1305 createPhotoAsset(displayName: string, albumUri?: string): Promise<FileAsset>; 1306 /** 1307 * Create Photo Asset 1308 * 1309 * @permission ohos.permission.WRITE_IMAGEVIDEO 1310 * @param { string } displayName - File name 1311 * @param { PhotoCreateOptions } createOption - Create operation 1312 * @returns { Promise<FileAsset> } A Promise instance used to return the FileAsset 1313 * @throws { BusinessError } 13900020 - if type displayName is not string 1314 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1315 * @systemapi 1316 * @since 9 1317 */ 1318 createPhotoAsset(displayName: string, createOption: PhotoCreateOptions): Promise<FileAsset>; 1319 /** 1320 * Create Photo Asset 1321 * 1322 * @permission ohos.permission.WRITE_IMAGEVIDEO 1323 * @param { string } displayName - File name 1324 * @param { PhotoCreateOptions } createOption - Photo create operation 1325 * @param { AsyncCallback<FileAsset> } callback - Callback used to return the FileAsset 1326 * @throws { BusinessError } 13900020 - if type displayName is not string 1327 * @throws { BusinessError } 14000001 - if type displayName invalid 1328 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1329 * @systemapi 1330 * @since 9 1331 */ 1332 createPhotoAsset(displayName: string, createOption: PhotoCreateOptions, callback: AsyncCallback<FileAsset>): void; 1333 /** 1334 * Create Audio Asset 1335 * 1336 * @permission ohos.permission.WRITE_AUDIO 1337 * @param { string } displayName - File name 1338 * @param { AsyncCallback<FileAsset> } callback - Callback used to return the FileAsset 1339 * @throws { BusinessError } 13900020 - if type displayName is not string 1340 * @throws { BusinessError } 14000001 - if type displayName invalid 1341 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1342 * @systemapi 1343 * @since 10 1344 */ 1345 createAudioAsset(displayName: string, callback: AsyncCallback<FileAsset>): void; 1346 /** 1347 * Create Audio Asset 1348 * 1349 * @permission ohos.permission.WRITE_AUDIO 1350 * @param { string } displayName - File name 1351 * @returns { Promise<FileAsset> } A Promise instance used to return the FileAsset 1352 * @throws { BusinessError } 13900020 - if type displayName is not string 1353 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1354 * @systemapi 1355 * @since 10 1356 */ 1357 createAudioAsset(displayName: string): Promise<FileAsset>; 1358 /** 1359 * Obtains albums based on the retrieval options. This method uses an asynchronous callback to return. 1360 * 1361 * @permission ohos.permission.READ_IMAGEVIDEO 1362 * @param { AlbumFetchOptions } options - Retrieval options. 1363 * @param { AsyncCallback<FetchResult<Album>> } callback - Callback used to return an album array. 1364 * @throws { BusinessError } 13900020 - if type options is not AlbumFetchOptions 1365 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1366 * @systemapi 1367 * @since 9 1368 */ 1369 getPhotoAlbums(options: AlbumFetchOptions, callback: AsyncCallback<FetchResult<Album>>): void; 1370 /** 1371 * Obtains albums based on the retrieval options. This method uses a promise to return the albums. 1372 * 1373 * @permission ohos.permission.READ_IMAGEVIDEO 1374 * @param { AlbumFetchOptions } options - Retrieval options. 1375 * @returns { Promise<FetchResult<Album>> } A Promise instance used to return an album array. 1376 * @throws { BusinessError } 13900020 - if type options is not AlbumFetchOptions 1377 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1378 * @systemapi 1379 * @since 9 1380 */ 1381 getPhotoAlbums(options: AlbumFetchOptions): Promise<FetchResult<Album>>; 1382 /** 1383 * Create a generic user album. 1384 * 1385 * @permission ohos.permission.WRITE_IMAGEVIDEO 1386 * @param { string } name - Album name to be created. 1387 * @param { AsyncCallback<Album> } callback - Returns the instance of newly created Album 1388 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1389 * @systemapi 1390 * @since 10 1391 */ 1392 createAlbum(name: string, callback: AsyncCallback<Album>): void; 1393 /** 1394 * Create a generic user album. 1395 * 1396 * @permission ohos.permission.WRITE_IMAGEVIDEO 1397 * @param { string } name - Album name to be created. 1398 * @returns { Promise<Album> } Returns the instance of newly created Album 1399 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1400 * @systemapi 1401 * @since 10 1402 */ 1403 createAlbum(name: string): Promise<Album>; 1404 /** 1405 * Delete generic user-created albums. 1406 * 1407 * @permission ohos.permission.WRITE_IMAGEVIDEO 1408 * @param { Array<Album> } albums - Specify which album to delete 1409 * @param { AsyncCallback<void> } callback - Returns void 1410 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1411 * @systemapi 1412 * @since 10 1413 */ 1414 deleteAlbums(albums: Array<Album>, callback: AsyncCallback<void>): void; 1415 /** 1416 * Delete generic user-created albums. 1417 * 1418 * @permission ohos.permission.WRITE_IMAGEVIDEO 1419 * @param { Array<Album> } albums - Specify which album to delete 1420 * @returns { Promise<void> } Returns the promise 1421 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1422 * @systemapi 1423 * @since 10 1424 */ 1425 deleteAlbums(albums: Array<Album>): Promise<void>; 1426 /** 1427 * Obtains albums based on the retrieval options and album types. 1428 * 1429 * @permission ohos.permission.READ_IMAGEVIDEO 1430 * @param { AlbumType } type - Album type. 1431 * @param { AlbumSubType } subType - Album subtype. 1432 * @param { FetchOptions } options - options to fetch albums 1433 * @param { AsyncCallback<FetchResult<Album>> } callback - Returns the fetch result of the albums 1434 * @throws { BusinessError } 13900020 - if type options is not FetchOption 1435 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1436 * @systemapi 1437 * @since 10 1438 */ 1439 getAlbums( 1440 type: AlbumType, 1441 subType: AlbumSubType, 1442 options: FetchOptions, 1443 callback: AsyncCallback<FetchResult<Album>> 1444 ): void; 1445 /** 1446 * Obtains albums based on the album types. 1447 * 1448 * @permission ohos.permission.READ_IMAGEVIDEO 1449 * @param { AlbumType } type - Album type. 1450 * @param { AlbumSubType } subType - Album subtype. 1451 * @param { AsyncCallback<FetchResult<Album>> } callback - Returns the fetch result of the albums 1452 * @throws { BusinessError } 13900020 - if type options is not FetchOption 1453 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1454 * @systemapi 1455 * @since 10 1456 */ 1457 getAlbums(type: AlbumType, subType: AlbumSubType, callback: AsyncCallback<FetchResult<Album>>): void; 1458 /** 1459 * Obtains albums based on the retrieval options and album types. 1460 * 1461 * @permission ohos.permission.READ_IMAGEVIDEO 1462 * @param { AlbumType } type - Album type. 1463 * @param { AlbumSubType } subType - Album subtype. 1464 * @param { FetchOptions } [options] -options to fetch albums 1465 * @returns { Promise<FetchResult<Album>> } - Returns the fetch result of the albums 1466 * @throws { BusinessError } 13900020 - if type options is not FetchOption 1467 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1468 * @systemapi 1469 * @since 10 1470 */ 1471 getAlbums(type: AlbumType, subType: AlbumSubType, options?: FetchOptions): Promise<FetchResult<Album>>; 1472 /** 1473 * Obtains system private albums based on the private album type. This method uses an asynchronous callback to return. 1474 * 1475 * @permission ohos.permission.READ_IMAGEVIDEO 1476 * @param { PrivateAlbumType } type - Private album type 1477 * @param { AsyncCallback<FetchResult<PrivateAlbum>> } callback - Used to return a private album FetchResult. 1478 * @throws { BusinessError } 13900020 - if type type is not PrivateAlbumType 1479 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1480 * @systemapi 1481 * @since 9 1482 */ 1483 getPrivateAlbum(type: PrivateAlbumType, callback: AsyncCallback<FetchResult<PrivateAlbum>>): void; 1484 /** 1485 * Obtains system private albums based on the private album type. This method uses a promise to return. 1486 * 1487 * @permission ohos.permission.READ_IMAGEVIDEO 1488 * @param { PrivateAlbumType } type - Private album type 1489 * @returns { Promise<FetchResult<PrivateAlbum>> } A Promise instance used to return a private album FetchResult. 1490 * @throws { BusinessError } 13900020 - if type type is not PrivateAlbumType 1491 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1492 * @systemapi 1493 * @since 9 1494 */ 1495 getPrivateAlbum(type: PrivateAlbumType): Promise<FetchResult<PrivateAlbum>>; 1496 /** 1497 * Query audio assets 1498 * 1499 * @permission ohos.permission.READ_AUDIO 1500 * @param { FetchOptions } options - Retrieval options. 1501 * @param { AsyncCallback<FetchResult<FileAsset>> } callback - Callback return the FetchResult. 1502 * @throws { BusinessError } 13900020 - if type options is not FetchOptions 1503 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1504 * @systemapi 1505 * @since 9 1506 */ 1507 getAudioAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<FileAsset>>): void; 1508 /** 1509 * Query audio assets 1510 * 1511 * @permission ohos.permission.READ_AUDIO 1512 * @param { FetchOptions } options - Retrieval options. 1513 * @returns { Promise<FetchResult<FileAsset>> } A promise instance used to return the files in the format of a FetchResult instance 1514 * @throws { BusinessError } 13900020 - if type options is not FetchOptions 1515 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1516 * @systemapi 1517 * @since 9 1518 */ 1519 getAudioAssets(options: FetchOptions): Promise<FetchResult<FileAsset>>; 1520 /** 1521 * Delete Asset 1522 * 1523 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 1524 * @param { string } uri - Uri of FileAsset 1525 * @param { AsyncCallback<void> } callback - No value returned 1526 * @throws { BusinessError } 13900020 - if type uri is not string 1527 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1528 * @systemapi 1529 * @since 9 1530 */ 1531 delete(uri: string, callback: AsyncCallback<void>): void; 1532 /** 1533 * Delete Asset 1534 * 1535 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 1536 * @param { string } uri - Uri of FileAsset 1537 * @returns { Promise<void> } A Promise instance, no value returned 1538 * @throws { BusinessError } 13900020 - if type uri is not string 1539 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1540 * @systemapi 1541 * @since 9 1542 */ 1543 delete(uri: string): Promise<void>; 1544 /** 1545 * Get the index of the asset in the album 1546 * 1547 * @permission ohos.permission.READ_IMAGEVIDEO 1548 * @param { string } photoUri - The photo asset uri. 1549 * @param { string } albumUri - The album uri. 1550 * @param { FetchOptions } options - fetch options 1551 * @param { AsyncCallback<number> } callback - Returns the index of the asset in the album 1552 * @throws { BusinessError } 401 - if parameter is invalid 1553 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1554 * @systemapi 1555 * @since 10 1556 */ 1557 getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback<number>): void; 1558 /** 1559 * Get the index of the asset in the album 1560 * 1561 * @permission ohos.permission.READ_IMAGEVIDEO 1562 * @param { string } photoUri - The photo asset uri. 1563 * @param { string } albumUri - The album uri. 1564 * @param { FetchOptions } options - fetch options 1565 * @returns { Promise<number> } - Returns the index of the asset in the album 1566 * @throws { BusinessError } 401 - if parameter is invalid 1567 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1568 * @systemapi 1569 * @since 10 1570 */ 1571 getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise<number>; 1572 /** 1573 * Turn on monitor the data changes 1574 * 1575 * @param { ChangeEvent } type - One of 'deviceChange','albumChange','imageChange','audioChange','videoChange','remoteFileChange' 1576 * @param { Callback<void> } callback - No value returned 1577 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1578 * @systemapi 1579 * @since 9 1580 */ 1581 on(type: ChangeEvent, callback: Callback<void>): void; 1582 /** 1583 * Turn off monitor the data changes 1584 * 1585 * @param { ChangeEvent } type - One of 'deviceChange','albumChange','imageChange','audioChange','videoChange','remoteFileChange' 1586 * @param { Callback<void> } callback - No value returned 1587 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1588 * @systemapi 1589 * @since 9 1590 */ 1591 off(type: ChangeEvent, callback?: Callback<void>): void; 1592 /** 1593 * Turn on monitor for the specified uri. 1594 * 1595 * @param { string } uri - FileAsset's uri, album's uri or DefaultChangeUri 1596 * @param { boolean } forSubUri - Monitor the sub uri. 1597 * @param { Callback<ChangeData> } callback - callback function, return the ChangeData to be monitored 1598 * @throws { BusinessError } 13900020 - if parameter is invalid 1599 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1600 * @systemapi 1601 * @since 10 1602 */ 1603 on(uri: string, forSubUri: boolean, callback: Callback<ChangeData>): void; 1604 /** 1605 * Turn off monitor for the specified uri. 1606 * 1607 * @param { string } uri - FileAsset's uri, Album's uri or DefaultChangeUri value 1608 * @param { Callback<ChangeData> } [callback] - Remove specified callback from monitoring to a specified uri 1609 * @throws { BusinessError } 13900020 - if parameter is invalid 1610 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1611 * @systemapi 1612 * @since 10 1613 */ 1614 off(uri: string, callback?: Callback<ChangeData>): void; 1615 /** 1616 * Get Active Peer device information 1617 * 1618 * @param { AsyncCallback<Array<PeerInfo>> } callback - Callback return the list of the active peer devices' information 1619 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 1620 * @systemapi 1621 * @since 9 1622 */ 1623 getActivePeers(callback: AsyncCallback<Array<PeerInfo>>): void; 1624 /** 1625 * Get Active Peer device information 1626 * 1627 * @returns { Promise<Array<PeerInfo>> } Promise used to return the list of the active peer devices' information 1628 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 1629 * @systemapi 1630 * @since 9 1631 */ 1632 getActivePeers(): Promise<Array<PeerInfo>>; 1633 /** 1634 * Get all the peer devices' information 1635 * 1636 * @param { AsyncCallback<Array<PeerInfo>> } callback - Callback return the list of the all the peer devices' information 1637 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 1638 * @systemapi 1639 * @since 9 1640 */ 1641 getAllPeers(callback: AsyncCallback<Array<PeerInfo>>): void; 1642 /** 1643 * Get all the peer devices' information 1644 * 1645 * @returns { Promise<Array<PeerInfo>> } Promise used to return the list of the all the peer devices' information 1646 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 1647 * @systemapi 1648 * @since 9 1649 */ 1650 getAllPeers(): Promise<Array<PeerInfo>>; 1651 /** 1652 * Release UserFileManager instance 1653 * 1654 * @param { AsyncCallback<void> } callback - No value returned 1655 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1656 * @systemapi 1657 * @since 9 1658 */ 1659 release(callback: AsyncCallback<void>): void; 1660 /** 1661 * Release UserFileManager instance 1662 * 1663 * @returns { Promise<void> } Return promise 1664 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1665 * @systemapi 1666 * @since 9 1667 */ 1668 release(): Promise<void>; 1669 } 1670 1671 /** 1672 * NotifyType subtype 1673 * 1674 * @enum { number } NotifyType subtype 1675 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1676 * @systemapi 1677 * @since 10 1678 */ 1679 enum NotifyType { 1680 /** 1681 * Type for add notification of the FileAsset or Album 1682 * 1683 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1684 * @systemapi 1685 * @since 10 1686 */ 1687 NOTIFY_ADD, 1688 /** 1689 * Type for update notification of the FileAsset or Album 1690 * 1691 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1692 * @systemapi 1693 * @since 10 1694 */ 1695 NOTIFY_UPDATE, 1696 /** 1697 * Type for remove notification of the FileAsset or Album 1698 * 1699 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1700 * @systemapi 1701 * @since 10 1702 */ 1703 NOTIFY_REMOVE, 1704 /** 1705 * Type for notification of the FileAsset added at an Album 1706 * 1707 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1708 * @systemapi 1709 * @since 10 1710 */ 1711 NOTIFY_ALBUM_ADD_ASSET, 1712 /** 1713 * Type for notification of the FileAsset removed at an Album 1714 * 1715 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1716 * @systemapi 1717 * @since 10 1718 */ 1719 NOTIFY_ALBUM_REMOVE_ASSET 1720 } 1721 1722 /** 1723 * DefaultChangeUri subtype 1724 * 1725 * @enum { string } DefaultChangeUri subtype 1726 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1727 * @systemapi 1728 * @since 10 1729 */ 1730 enum DefaultChangeUri { 1731 /** 1732 * Uri for default PhotoAsset, use with forDescendant{true}, will recieve all PhotoAsset's change notifications 1733 * 1734 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1735 * @systemapi 1736 * @since 10 1737 */ 1738 DEFAULT_PHOTO_URI, 1739 /** 1740 * Uri for default Album, use with forDescendant{true}, will recieve all Album's change notifications 1741 * 1742 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1743 * @systemapi 1744 * @since 10 1745 */ 1746 DEFAULT_ALBUM_URI, 1747 /** 1748 * Uri for default AudioAsset, use with forDescendant{true}, will recieve all AudioAsset's change notifications 1749 * 1750 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1751 * @systemapi 1752 * @since 10 1753 */ 1754 DEFAULT_AUDIO_URI 1755 } 1756 1757 /** 1758 * the value of the monitor callback function 1759 * 1760 * @interface ChangeData 1761 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1762 * @systemapi 1763 * @since 10 1764 */ 1765 interface ChangeData { 1766 /** 1767 * the NotifyType of ChangeData 1768 * 1769 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1770 * @systemapi 1771 * @since 10 1772 */ 1773 type: NotifyType; 1774 /** 1775 * all uris of the same NotifyType, could be FileAssets' or Albums' 1776 * 1777 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1778 * @systemapi 1779 * @since 10 1780 */ 1781 uris: Array<string>; 1782 /** 1783 * change details of the Album's FileAssets when uris is the Album's uri type 1784 * 1785 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1786 * @systemapi 1787 * @since 10 1788 */ 1789 subUris: Array<string>; 1790 } 1791 1792 /** 1793 * Peer devices' information 1794 * 1795 * @interface PeerInfo 1796 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 1797 * @systemapi 1798 * @since 9 1799 */ 1800 interface PeerInfo { 1801 /** 1802 * Peer device name 1803 * 1804 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 1805 * @systemapi 1806 * @since 9 1807 */ 1808 readonly deviceName: string; 1809 /** 1810 * Peer device network id 1811 * 1812 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 1813 * @systemapi 1814 * @since 9 1815 */ 1816 readonly networkId: string; 1817 /** 1818 * Peer device online status 1819 * 1820 * @syscap SystemCapability.FileManagement.UserFileManager.DistributedCore 1821 * @systemapi 1822 * @since 9 1823 */ 1824 readonly isOnline: boolean; 1825 } 1826 1827 /** 1828 * Private album type 1829 * 1830 * @enum { string } PrivateAlbumType 1831 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1832 * @systemapi 1833 * @since 9 1834 */ 1835 enum PrivateAlbumType { 1836 /** 1837 * System Private Album: Favorite album 1838 * 1839 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1840 * @systemapi 1841 * @since 9 1842 */ 1843 TYPE_FAVORITE, 1844 /** 1845 * System Private Album: Trash album 1846 * 1847 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1848 * @systemapi 1849 * @since 9 1850 */ 1851 TYPE_TRASH 1852 } 1853 1854 /** 1855 * Defines the private album 1856 * 1857 * @interface PrivateAlbum 1858 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1859 * @systemapi 1860 * @since 9 1861 */ 1862 interface PrivateAlbum extends AbsAlbum { 1863 /** 1864 * Delete asset permanently from Trash bin, only support the Trash album 1865 * 1866 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 1867 * @param { string } uri - uri of asset 1868 * @param { AsyncCallback<void> } callback - No value returned 1869 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1870 * @systemapi 1871 * @since 9 1872 */ 1873 delete(uri: string, callback: AsyncCallback<void>): void; 1874 /** 1875 * Delete asset permanently from Trash bin, only support the Trash album 1876 * 1877 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 1878 * @param { string } uri - Uri of asset 1879 * @returns { Promise<void> } A Promise instance, no value returned 1880 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1881 * @systemapi 1882 * @since 9 1883 */ 1884 delete(uri: string): Promise<void>; 1885 /** 1886 * Recover asset from Trash bin, only support the Trash album 1887 * 1888 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 1889 * @param { string } uri - Uri of asset 1890 * @param { AsyncCallback<void> } callback - No value returned 1891 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1892 * @systemapi 1893 * @since 9 1894 */ 1895 recover(uri: string, callback: AsyncCallback<void>): void; 1896 /** 1897 * Recover asset from Trash bin, only support the Trash album 1898 * 1899 * @permission ohos.permission.READ_IMAGEVIDEO and ohos.permission.WRITE_IMAGEVIDEO or ohos.permission.READ_AUDIO and ohos.permission.WRITE_AUDIO 1900 * @param { string } uri - Uri of asset 1901 * @returns { Promise<void> } A Promise instance, no value returned 1902 * @syscap SystemCapability.FileManagement.UserFileManager.Core 1903 * @systemapi 1904 * @since 9 1905 */ 1906 recover(uri: string): Promise<void>; 1907 } 1908} 1909 1910export default userFileManager; 1911