diff --git a/AppScope/resources/base/media/app_icon.png b/AppScope/resources/base/media/app_icon.png index ce307a8827bd75456441ceb57d530e4c8d45d36c..a39445dc87828b76fed6d2ec470dd455c45319e3 100644 Binary files a/AppScope/resources/base/media/app_icon.png and b/AppScope/resources/base/media/app_icon.png differ diff --git a/README.md b/README.md index 47bc09b6723ea5eedf424c0cbae8a6a33ffe2c57..631506625a06b410fe3c4ad05f55f176c63a42c2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 网络-上传和下载(ArkTS) +# 上传和下载 ### 介绍 本示例使用@ohos.request接口创建上传和下载任务,实现上传、下载功能,hfs作为服务器,实现了文件的上传和下载和任务的查询功能。 @@ -11,25 +11,25 @@ 使用说明 -1.本示例功能需要先配置服务器环境后使用,具体配置见[上传下载服务配置](./environment)。 +1. 本示例功能需要先配置服务器环境后使用,具体配置见[上传下载服务配置](./environment)。 -2.首页展示上传和下载两个入口组件,点击进入对应的页面,如果要使用后台下载任务,请开启后台任务开关。 +2. 首页展示上传和下载两个入口组件,点击进入对应的页面,如果要使用后台下载任务,请开启后台任务开关。 -3.上传页面(请先在图库中确定已开启图库权限): +3. 上传页面(请先在图库中确定已开启图库权限): -​ 点击**+**,**从相册选择**拉起图库选择照片,图片选择页面支持拍照,选择照片后点击发表进行上传。 + 3.1 点击**+**,**从相册选择**拉起图库选择照片,图片选择页面支持拍照,选择照片后点击发表进行上传。 + + 3.2 在首页中打开后台任务开关后,上传页面开启的是后台上传任务,后台任务在应用退出到后台时可以在通知栏看到任务状态。 -​ 在首页中打开后台任务开关后,上传页面开启的是后台上传任务,后台任务在应用退出到后台时可以在通知栏看到任务状态。 +4. 下载页面: -4.下载页面: + 4.1 点击文件列表选择要下载的文件后,点击**下载**选择指定路径后开始下载。 -​ 点击文件列表选择要下载的文件后,点击**下载**选择指定路径后开始下载。 + 4.2 点击**查看下载文件**进入下载文件页面,点击文件夹查看文件夹内的文件。 -​ 点击**查看下载文件**进入下载文件页面,点击文件夹查看文件夹内的文件。 + 4.3 在首页中打开后台任务开关后,下载页面开启的是后台下载任务,后台任务在应用退出到后台时可以在通知栏看到任务状态。 -​ 在首页中打开后台任务开关后,下载页面开启的是后台下载任务,后台任务在应用退出到后台时可以在通知栏看到任务状态。 - -​ 前台下载时只支持单文件下载,后台下载时支持选择多个文件下载。 + 4.4 前台下载时只支持单文件下载,后台下载时支持选择多个文件下载。 ### 工程目录 @@ -82,9 +82,7 @@ ### 相关权限 -ohos.permission.INTERNET - -ohos.permission.READ_MEDIA +ohos.permission.INTERNET:允许应用在上传下载场景中访问网络 ### 依赖 diff --git a/entry/src/main/ets/components/AddPictures.ets b/entry/src/main/ets/components/AddPictures.ets index b4309becf5dac4546390bf90386be280fa397319..884dce44d0716be1930cdb52bbbacb022ed32cae 100644 --- a/entry/src/main/ets/components/AddPictures.ets +++ b/entry/src/main/ets/components/AddPictures.ets @@ -16,10 +16,12 @@ import { picker } from '@kit.CoreFileKit'; import { logger } from '@ohos/uploaddownload'; import { BusinessError } from '@kit.BasicServicesKit'; +import { photoAccessHelper } from '@kit.MediaLibraryKit'; const TAG: string = 'AddPictures'; -@Extend(Image) function imageStyle() { +@Extend(Image) +function imageStyle() { .width('100%') .aspectRatio(1) .objectFit(ImageFit.Fill) @@ -28,6 +30,7 @@ const TAG: string = 'AddPictures'; } const TEXT_WIDTH_FULL: Length = '100%'; + @Component export struct AddPictures { @Consume imageList: Array; @@ -48,7 +51,7 @@ export struct AddPictures { Image(item) .imageStyle() } - }) + }, (item: string, index: number) => index + item) GridCol({ span: 1 }) { Row() { Image($r('app.media.ic_public_add')) @@ -96,10 +99,10 @@ export struct AddPictures { fontColor: $r('app.color.btn_text_blue'), action: () => { try { - let photoSelectOptions = new picker.PhotoSelectOptions(); - photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; + let photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); + photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; photoSelectOptions.maxSelectNumber = 5; - let photoPicker = new picker.PhotoViewPicker(); + let photoPicker = new photoAccessHelper.PhotoViewPicker(); photoPicker.select(photoSelectOptions).then((photoSelectResult: picker.PhotoSelectResult) => { this.addImages(photoSelectResult.photoUris); }).catch((err: BusinessError) => { diff --git a/entry/src/main/ets/components/SelectFolderDialog.ets b/entry/src/main/ets/components/SelectFolderDialog.ets index c32bc1a31ac59a35669d1763cee7370403511691..d9172517a05816562083494a37c3ec7e1a0135f4 100644 --- a/entry/src/main/ets/components/SelectFolderDialog.ets +++ b/entry/src/main/ets/components/SelectFolderDialog.ets @@ -32,12 +32,14 @@ const BUTTON_MARGIN: Length | Padding = 5; const RADIO_SIZE: Length = 20; const MARGIN_BUTTON: Length = 12; const TEXT_HEIGHT: Length = 56; + @CustomDialog export struct SelectFolderDialog { @Consume downloadFolder: Array; @State selectedFolder: string = ''; private controller: CustomDialogController = new CustomDialogController({ builder: null }); - private selectFolder: (folder: string) => void = () => {}; + private selectFolder: (folder: string) => void = () => { + }; build() { Column() { @@ -59,8 +61,10 @@ export struct SelectFolderDialog { .fontSize(TEXT_FONT_SIZE) Blank() Radio({ group: 'folder', value: item }) - .size({ width: RADIO_SIZE, - height: RADIO_SIZE }) + .size({ + width: RADIO_SIZE, + height: RADIO_SIZE + }) .checked(item === this.selectedFolder) .radioStyle({ checkedBackgroundColor: $r('app.color.button_blue') }) .onChange((isCheck: boolean) => { @@ -76,7 +80,7 @@ export struct SelectFolderDialog { this.selectedFolder = item; logger.info(TAG, `this.selectedFolder = ${this.selectedFolder}`); }) - }) + }, (item: string, index: number) => index + item) Row() { Button() { Text($r('app.string.cancel')) @@ -114,11 +118,15 @@ export struct SelectFolderDialog { } .width(FULL_WIDTH) .alignItems(HorizontalAlign.Start) - .border({ color: Color.Gray, - radius: BORDER_RADIUS }) - .padding({ left: PADDING_LEFT, + .border({ + color: Color.Gray, + radius: BORDER_RADIUS + }) + .padding({ + left: PADDING_LEFT, right: PADDING_RIGHT, top: PADDING_TOP, - bottom: PADDING_BUTTON }) + bottom: PADDING_BUTTON + }) } } \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 7a6a5f6d0f0b9369a378c10a7e7596400fe0742a..9ac360d8dedf373b30d4f4134ea167dad9eafc49 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -13,29 +13,16 @@ * limitations under the License. */ -import { UIAbility, AbilityConstant, Want, abilityAccessCtrl, Permissions } from '@kit.AbilityKit'; +import { UIAbility, AbilityConstant, Want } from '@kit.AbilityKit'; import { window } from '@kit.ArkUI'; import { logger, urlUtils } from '@ohos/uploaddownload'; -const PERMISSIONS: Array = ['ohos.permission.READ_MEDIA']; const TAG: string = 'EntryAbility'; const URL: string = 'http://xxx.xxx.xxx.xxx:8080/'; export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { logger.info(TAG, 'Ability onCreate'); - let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); - try { - atManager.requestPermissionsFromUser(this.context, PERMISSIONS, (err, data) => { - if (err) { - logger.info(TAG, `requestPermissionsFromUser data: ${JSON.stringify(err)}`); - } else { - logger.info(TAG, `requestPermissionsFromUser data: ${JSON.stringify(data)}`); - } - }); - } catch (err) { - logger.info(TAG, `catch err->${JSON.stringify(err)}`); - } } onDestroy(): void { diff --git a/entry/src/main/ets/pages/Download.ets b/entry/src/main/ets/pages/Download.ets index b380de07ef7da0397d9cad6f7849211897310656..02347d2c51b90e8df0803d520b80e4a9a4316ac9 100644 --- a/entry/src/main/ets/pages/Download.ets +++ b/entry/src/main/ets/pages/Download.ets @@ -93,7 +93,7 @@ struct Download { ListItem() { this.FileItem(item, index) } - }, (item: FileModel) => JSON.stringify(item)) + }, (item: FileModel, index: number) => index + item.name) } .width(LIST_WIDTH) .height(LIST_HEIGHT) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index abc14eedef6e3efae9da35d17d999cc74fd1d20a..b4247fc8fd8a4a4f07ba6f3b9b3507e2daab45cb 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -39,7 +39,7 @@ struct Index { @StorageLink('isBackground') isBackground: boolean = false; aboutToAppear() { - notificationManager.requestEnableNotification(); + notificationManager.requestEnableNotification(getContext(this) as common.UIAbilityContext); } build() { diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 index 3feb50ca568e2c53f5829ea98a077dba676a9abb..4186a910e7b5f69d0cf9c82b1c4f985e77c21e51 100644 --- a/entry/src/main/module.json5 +++ b/entry/src/main/module.json5 @@ -29,9 +29,9 @@ "name": "EntryAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", - "icon": "$media:icon", + "icon": "$media:layered_image", "label": "$string:EntryAbility_label", - "startWindowIcon": "$media:icon", + "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", "exported": true, "skills": [ @@ -47,16 +47,6 @@ } ], "requestPermissions": [ - { - "name": "ohos.permission.READ_MEDIA", - "reason": "$string:media_permission", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - "when": "inuse" - } - }, { "name": "ohos.permission.INTERNET", "reason": "$string:media_internet_permission", diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 8987748e611b3f7a05b9889cd6e8ab46a9529601..1a5a841bf5e3775c75a4cc6dae0b9d11bf008d84 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -96,13 +96,9 @@ "name": "continue", "value": "Continue" }, - { - "name": "media_permission", - "value": "Allows the app to read media file information from the user's external storage" - }, { "name": "media_internet_permission", - "value": "Allow access to the network" + "value": "Allow applications to access the network in upload and download scenarios." }, { "name": "background_tips", diff --git a/entry/src/main/resources/base/media/background.png b/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..f939c9fa8cc8914832e602198745f592a0dfa34d Binary files /dev/null and b/entry/src/main/resources/base/media/background.png differ diff --git a/entry/src/main/resources/base/media/foreground.png b/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..4483ddad1f079e1089d685bd204ee1cfe1d01902 Binary files /dev/null and b/entry/src/main/resources/base/media/foreground.png differ diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/entry/src/main/resources/base/media/icon.png and /dev/null differ diff --git a/entry/src/main/resources/base/media/layered_image.json b/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/startIcon.png b/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/entry/src/main/resources/base/media/startIcon.png differ diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json index 3a156f6366954a96d7ca91860088fe1396f10cd6..2e5be270bb341b0182051b9b9f2012ddfd70573a 100644 --- a/entry/src/main/resources/en_US/element/string.json +++ b/entry/src/main/resources/en_US/element/string.json @@ -96,13 +96,9 @@ "name": "continue", "value": "Continue" }, - { - "name": "media_permission", - "value": "Allows the app to read media file information from the user's external storage" - }, { "name": "media_internet_permission", - "value": "Allow access to the network" + "value": "Allow applications to access the network in upload and download scenarios." }, { "name": "background_tips", diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json index 80d2a521696f91a4e3c8fe05275b0db8c290b127..4ff3644e2450a30b67bebc4dc622385f4631bfc2 100644 --- a/entry/src/main/resources/zh_CN/element/string.json +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -96,13 +96,9 @@ "name": "continue", "value": "继续" }, - { - "name": "media_permission", - "value": "允许应用读取用户外部存储中的媒体文件信息" - }, { "name": "media_internet_permission", - "value": "允许访问网络" + "value": "允许应用在上传下载场景中访问网络" }, { "name": "background_tips", diff --git a/features/uploadanddownload/src/main/ets/components/FileBrowse.ets b/features/uploadanddownload/src/main/ets/components/FileBrowse.ets index e8fd253d4cde3ad9e0a022cf7610d1d5add62ae5..77d27cfce4f82618b6a4eac5506c8647a87ca8e1 100644 --- a/features/uploadanddownload/src/main/ets/components/FileBrowse.ets +++ b/features/uploadanddownload/src/main/ets/components/FileBrowse.ets @@ -61,7 +61,7 @@ export struct FileBrowse { } }) } - }) + }, (item: string, index: number) => index + item) } .padding({ left: 12, right: 12 }) } @@ -107,7 +107,7 @@ export struct FileBrowse { .height(48) .backgroundColor(Color.White) .borderRadius(24) - }) + }, (item: string, index: number) => index + item) } .padding({ left: 12, right: 12 }) .layoutWeight(1) diff --git a/features/uploadanddownload/src/main/module.json5 b/features/uploadanddownload/src/main/module.json5 index 607d284dc6b0de8ba0f35de7a2e184c406e92674..dd058680687563e01a7d0e3915778b4a96f4fa9a 100644 --- a/features/uploadanddownload/src/main/module.json5 +++ b/features/uploadanddownload/src/main/module.json5 @@ -20,16 +20,6 @@ "phone" ], "requestPermissions": [ - { - "name": "ohos.permission.READ_MEDIA", - "reason": "$string:media_permission", - "usedScene": { - "abilities": [ - "EntryAbility" - ], - "when": "inuse" - } - }, { "name": "ohos.permission.INTERNET", "reason": "$string:media_internet_permission", diff --git a/features/uploadanddownload/src/main/resources/base/element/string.json b/features/uploadanddownload/src/main/resources/base/element/string.json index 237a21dede6e56fa3e8a71e6397d3ae5fb37f5d4..2e3d3bdb4db2c09c81aa4c612397108b75d4d3c0 100644 --- a/features/uploadanddownload/src/main/resources/base/element/string.json +++ b/features/uploadanddownload/src/main/resources/base/element/string.json @@ -20,13 +20,9 @@ "name": "clear_folder", "value": "Clear folder" }, - { - "name": "media_permission", - "value": "Allows the app to read media file information from the user's external storage" - }, { "name": "media_internet_permission", - "value": "Allow access to the network" + "value": "Allow applications to access the network in upload and download scenarios." }, { "name": "have_upload_task_tips", diff --git a/features/uploadanddownload/src/main/resources/en_US/element/string.json b/features/uploadanddownload/src/main/resources/en_US/element/string.json index 237a21dede6e56fa3e8a71e6397d3ae5fb37f5d4..2e3d3bdb4db2c09c81aa4c612397108b75d4d3c0 100644 --- a/features/uploadanddownload/src/main/resources/en_US/element/string.json +++ b/features/uploadanddownload/src/main/resources/en_US/element/string.json @@ -20,13 +20,9 @@ "name": "clear_folder", "value": "Clear folder" }, - { - "name": "media_permission", - "value": "Allows the app to read media file information from the user's external storage" - }, { "name": "media_internet_permission", - "value": "Allow access to the network" + "value": "Allow applications to access the network in upload and download scenarios." }, { "name": "have_upload_task_tips", diff --git a/features/uploadanddownload/src/main/resources/zh_CN/element/string.json b/features/uploadanddownload/src/main/resources/zh_CN/element/string.json index 1abeb2e5b0a25098b40b0cccd3e0b15844bbd602..918f46a2bd782a5eee9d9beaf6900f65b3a828f3 100644 --- a/features/uploadanddownload/src/main/resources/zh_CN/element/string.json +++ b/features/uploadanddownload/src/main/resources/zh_CN/element/string.json @@ -20,13 +20,9 @@ "name": "clear_folder", "value": "清空文件夹" }, - { - "name": "media_permission", - "value": "允许应用读取用户外部存储中的媒体文件信息" - }, { "name": "media_internet_permission", - "value": "允许访问网络" + "value": "允许应用在上传下载场景中访问网络" }, { "name": "have_upload_task_tips",