Showing
1 changed file
with
10 additions
and
3 deletions
| @@ -53,7 +53,10 @@ export struct ImageDownloadComponent { | @@ -53,7 +53,10 @@ export struct ImageDownloadComponent { | ||
| 53 | } catch (error) { | 53 | } catch (error) { |
| 54 | const err: BusinessError = error as BusinessError; | 54 | const err: BusinessError = error as BusinessError; |
| 55 | //console.info(`Failed to save photo. Code is ${err.code}, message is ${err.message}`); | 55 | //console.info(`Failed to save photo. Code is ${err.code}, message is ${err.message}`); |
| 56 | - promptAction.showToast({ message: '保存图片失败!' }); | 56 | + if (this.isGranted) { |
| 57 | + promptAction.showToast({ message: '保存图片失败!' }); | ||
| 58 | + } | ||
| 59 | + | ||
| 57 | } | 60 | } |
| 58 | } | 61 | } |
| 59 | }) | 62 | }) |
| @@ -161,11 +164,12 @@ export struct ImageDownloadComponent { | @@ -161,11 +164,12 @@ export struct ImageDownloadComponent { | ||
| 161 | * @returns | 164 | * @returns |
| 162 | */ | 165 | */ |
| 163 | async saveImage(buffer: ArrayBuffer | string): Promise<void> { | 166 | async saveImage(buffer: ArrayBuffer | string): Promise<void> { |
| 164 | - //console.info(`cj2024 saveImage buffer ${buffer}`) | 167 | + //console.info(`cj2024 saveImage buffer ${buffer} isGranted = ${this.isGranted}`) |
| 165 | if (!this.isGranted) { | 168 | if (!this.isGranted) { |
| 166 | //跳转权限设置 | 169 | //跳转权限设置 |
| 167 | // const permissionUtil = new PermissionUtil(); | 170 | // const permissionUtil = new PermissionUtil(); |
| 168 | PermissionUtil.reqPermissionsFromUser(['ohos.permission.READ_MEDIA'], this).then((res) => { | 171 | PermissionUtil.reqPermissionsFromUser(['ohos.permission.READ_MEDIA'], this).then((res) => { |
| 172 | + //console.info(`cj2024 saveImage res ${res}`) | ||
| 169 | this.isGranted = res; | 173 | this.isGranted = res; |
| 170 | }); | 174 | }); |
| 171 | } else { | 175 | } else { |
| @@ -192,7 +196,10 @@ export struct ImageDownloadComponent { | @@ -192,7 +196,10 @@ export struct ImageDownloadComponent { | ||
| 192 | await asset.close(fd); | 196 | await asset.close(fd); |
| 193 | promptAction.showToast({ message: '已保存至相册!' }); | 197 | promptAction.showToast({ message: '已保存至相册!' }); |
| 194 | } else { | 198 | } else { |
| 195 | - promptAction.showToast({ message: '保存图片失败!' }); | 199 | + if (this.isGranted) { |
| 200 | + promptAction.showToast({ message: '保存图片失败!' }); | ||
| 201 | + } | ||
| 202 | + | ||
| 196 | throw new Error('Failed to create asset'); | 203 | throw new Error('Failed to create asset'); |
| 197 | } | 204 | } |
| 198 | } | 205 | } |
-
Please register or login to post a comment