1e41f4b71Sopenharmony_ci# SaveButton 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **SaveButton** security component allows you to obtain temporary storage permission from the user by their touching the button, eliminating the need for a permission request dialog box. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **NOTE** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> This component is supported since API version 10. Updates will be marked with a superscript to indicate their earliest API version. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Child Components 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciNot supported 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## APIs 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci### SaveButton 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ciSaveButton() 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciCreates a Save button with an icon, text, and background. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciYou may want to learn the [restrictions on security component styles](../../../security/AccessToken/security-component-overview.md#constraints) to avoid authorization failures caused by incompliant styles. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci### SaveButton 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciSaveButton(options:SaveButtonOptions) 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciCreates a Save button that contains the specified elements. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciYou may want to learn the [restrictions on security component styles](../../../security/AccessToken/security-component-overview.md#constraints) to avoid authorization failures caused by incompliant styles. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci**Parameters** 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 42e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 43e41f4b71Sopenharmony_ci| options | [SaveButtonOptions](#savebuttonoptions) | Yes| Creates a Save button that contains the specified elements.| 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci## SaveButtonOptions 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 52e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 53e41f4b71Sopenharmony_ci| icon | [SaveIconStyle](#saveiconstyle) | No| Icon style of the Save button.<br>If this parameter is not specified, no icon is contained. Either **icon** or **text**, or both, must be set.| 54e41f4b71Sopenharmony_ci| text | [SaveDescription](#savedescription) | No| Text on the Save button.<br>If this parameter is not specified, no text is contained. Either **icon** or **text**, or both, must be set.| 55e41f4b71Sopenharmony_ci| buttonType | [ButtonType](ts-basic-components-button.md#buttontype) | No| Background type of the Save button.<br>If this parameter is not specified, the system uses a capsule-type button as the Save button.| 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci## SaveIconStyle 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci| Name| Value| Description| 64e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 65e41f4b71Sopenharmony_ci| FULL_FILLED | 0 | Filled style icon.| 66e41f4b71Sopenharmony_ci| LINES | 1 | Line style icon.| 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci## SaveDescription 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci| Name| Value| Description| 73e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 74e41f4b71Sopenharmony_ci| DOWNLOAD | 0 | The text on the Save button is **Download**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 75e41f4b71Sopenharmony_ci| DOWNLOAD_FILE | 1 | The text on the Save button is **Download File**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 76e41f4b71Sopenharmony_ci| SAVE | 2 | The text on the Save button is **Save**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 77e41f4b71Sopenharmony_ci| SAVE_IMAGE | 3 | The text on the Save button is **Save Image**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 78e41f4b71Sopenharmony_ci| SAVE_FILE | 4 | The text on the Save button is **Save File**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 79e41f4b71Sopenharmony_ci| DOWNLOAD_AND_SHARE | 5 | The text on the Save button is **Download and Share**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 80e41f4b71Sopenharmony_ci| RECEIVE | 6 | The text on the Save button is **Receive**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 81e41f4b71Sopenharmony_ci| CONTINUE_TO_RECEIVE | 7 | The text on the Save button is **Continue**.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 82e41f4b71Sopenharmony_ci| SAVE_TO_GALLERY<sup>12+</sup> | 8 | The text on the Save button is **Save to Gallery**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 83e41f4b71Sopenharmony_ci| EXPORT_TO_GALLERY<sup>12+</sup> | 9 | The text on the Save button is **Export**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 84e41f4b71Sopenharmony_ci| QUICK_SAVE_TO_GALLERY<sup>12+</sup> | 10 | The text on the Save button is **Quick Save**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 85e41f4b71Sopenharmony_ci| RESAVE_TO_GALLERY<sup>12+</sup> | 11 | The text on the Save button is **Resave**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci## SaveButtonOnClickResult 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci| Name| Value| Description| 94e41f4b71Sopenharmony_ci| -------- | -------- | -------- | 95e41f4b71Sopenharmony_ci| SUCCESS | 0 | The Save button is touched successfully.| 96e41f4b71Sopenharmony_ci| TEMPORARY_AUTHORIZATION_FAILED | 1 | Temporary authorization fails after the Save button is touched.| 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci## Attributes 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ciThis component can only inherit the [universal attributes of security components](ts-securitycomponent-attributes.md). 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci## Events 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ciOnly the following events are supported. 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci### onClick 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_cionClick(event: (event: ClickEvent, result: SaveButtonOnClickResult) => void) 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ciCalled when a click event occurs. 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11. 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci**Parameters** 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci| Name| Type | Mandatory| Description | 119e41f4b71Sopenharmony_ci|------------|------|-------|---------| 120e41f4b71Sopenharmony_ci| event | [ClickEvent](ts-universal-events-click.md#clickevent) |Yes|See **ClickEvent**.| 121e41f4b71Sopenharmony_ci| result | [SaveButtonOnClickResult](#savebuttononclickresult)| Yes| Authorization result. The authorization is effective for 10 seconds. This means that, a specific media library API can be called, an unlimited number of times, within 10 seconds of the touch. If the API is not called within the 10 seconds, the authorization fails.| 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci## Example 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci```ts 126e41f4b71Sopenharmony_ci// xxx.ets 127e41f4b71Sopenharmony_ciimport { photoAccessHelper } from '@kit.MediaLibraryKit'; 128e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit'; 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci@Entry 131e41f4b71Sopenharmony_ci@Component 132e41f4b71Sopenharmony_cistruct Index { 133e41f4b71Sopenharmony_ci build() { 134e41f4b71Sopenharmony_ci Row() { 135e41f4b71Sopenharmony_ci Column({space:10}) { 136e41f4b71Sopenharmony_ci // Create a default Save button with an icon, text, and background. 137e41f4b71Sopenharmony_ci SaveButton().onClick(async (event:ClickEvent, result:SaveButtonOnClickResult) => { 138e41f4b71Sopenharmony_ci if (result == SaveButtonOnClickResult.SUCCESS) { 139e41f4b71Sopenharmony_ci try { 140e41f4b71Sopenharmony_ci const context = getContext(this); 141e41f4b71Sopenharmony_ci let helper = photoAccessHelper.getPhotoAccessHelper(context); 142e41f4b71Sopenharmony_ci // After onClick is triggered, the createAsset API can be called within 10 seconds to create an image file. After 10 seconds have elapsed, the permission to call createAsset is revoked. 143e41f4b71Sopenharmony_ci let uri = await helper.createAsset(photoAccessHelper.PhotoType.IMAGE, 'png'); 144e41f4b71Sopenharmony_ci // Use the URI to open the file. The write process is not time bound. 145e41f4b71Sopenharmony_ci let file = await fileIo.open(uri, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); 146e41f4b71Sopenharmony_ci // Write to the file. 147e41f4b71Sopenharmony_ci await fileIo.write(file.fd, "context"); 148e41f4b71Sopenharmony_ci // Close the file. 149e41f4b71Sopenharmony_ci await fileIo.close(file.fd); 150e41f4b71Sopenharmony_ci } catch (error) { 151e41f4b71Sopenharmony_ci console.error("error is "+ JSON.stringify(error)); 152e41f4b71Sopenharmony_ci } 153e41f4b71Sopenharmony_ci } 154e41f4b71Sopenharmony_ci }) 155e41f4b71Sopenharmony_ci // Whether the button has an icon, text, and background depends on whether the corresponding parameter is passed in. If buttonType is not passed in, the button uses the ButtonType.Capsule settings. 156e41f4b71Sopenharmony_ci SaveButton({icon:SaveIconStyle.FULL_FILLED}) 157e41f4b71Sopenharmony_ci // This button only has the icon and background. If the alpha value of the most significant eight bits of the background color is less than 0x1A, the system forcibly adjusts the alpha value to 0xFF. 158e41f4b71Sopenharmony_ci SaveButton({icon:SaveIconStyle.FULL_FILLED, buttonType:ButtonType.Capsule}) 159e41f4b71Sopenharmony_ci .backgroundColor(0x10007dff) 160e41f4b71Sopenharmony_ci // The button has an icon, text, and background. If the alpha value of the most significant eight bits of the background color is less than 0x1A, the system forcibly adjusts the alpha value to 0xFF. 161e41f4b71Sopenharmony_ci SaveButton({icon:SaveIconStyle.FULL_FILLED, text:SaveDescription.DOWNLOAD, buttonType:ButtonType.Capsule}) 162e41f4b71Sopenharmony_ci // Create a button with an icon, text, and background. If the set width is less than the minimum allowed, the button's text will wrap to guarantee full text display. 163e41f4b71Sopenharmony_ci SaveButton({icon:SaveIconStyle.FULL_FILLED, text:SaveDescription.DOWNLOAD, buttonType:ButtonType.Capsule}) 164e41f4b71Sopenharmony_ci .fontSize(16) 165e41f4b71Sopenharmony_ci .width(30) 166e41f4b71Sopenharmony_ci // Create a button with an icon, text, and background. If the set width is less than the minimum allowed, the button's text will wrap to guarantee full text display. 167e41f4b71Sopenharmony_ci SaveButton({icon:SaveIconStyle.FULL_FILLED, text:SaveDescription.DOWNLOAD, buttonType:ButtonType.Capsule}) 168e41f4b71Sopenharmony_ci .fontSize(16) 169e41f4b71Sopenharmony_ci .size({width: 30, height: 30}) 170e41f4b71Sopenharmony_ci // Create a button with an icon, text, and background. If the set width is less than the minimum allowed, the button's text will wrap to guarantee full text display. 171e41f4b71Sopenharmony_ci SaveButton({icon:SaveIconStyle.FULL_FILLED, text:SaveDescription.DOWNLOAD, buttonType:ButtonType.Capsule}) 172e41f4b71Sopenharmony_ci .fontSize(16) 173e41f4b71Sopenharmony_ci .constraintSize({minWidth: 0, maxWidth: 30, minHeight: 0, maxHeight: 30}) 174e41f4b71Sopenharmony_ci }.width('100%') 175e41f4b71Sopenharmony_ci }.height('100%') 176e41f4b71Sopenharmony_ci } 177e41f4b71Sopenharmony_ci} 178e41f4b71Sopenharmony_ci``` 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci 181