HarmonyOS ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY,自动签名无法自动申请

ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY,自动签名无法自动申请。导致开发期间应用无法安装。

操作步骤:

1、Entry的module.json5中添加ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY权限。

{
  "name": "ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY",
  "reason": "$string:permission_directory_reason",
  "usedScene": {
    "when": "always"
  }
}

2、项目结构-Project-SigningConfigs,勾选Automatically generate signature。

3、点击Apply按钮,不会弹出Notice。正常情况下申请受限权限会弹出Notice:

Note: You are applying for restricted ACL permissions: WRITE_IMAGEVIDEO, READ_IMAGEVIDEO. These permissions are subject to review together with your app release. For a faster review process, apply for the following permissions instead, if they are sufficient for your purposes: SaveButton, PhotoViewPicker. Permission Application Scenarios

4、运行项目报错:

Install Failed: error: failed to install bundle.
code:9568289
error: install failed due to grant request permissions failed.
View detailed instructions.
HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
fox280

ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY仅支持PC侧使用,手机侧访问文件管理器下文件只能使用DocumentViewPicker。参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/save-user-file-V5#保存文档类文件

参考示例:

import common from '@ohos.app.ability.common';
import request from '@ohos.request';
import { BusinessError } from '@ohos.base';
import picker from '@ohos.file.picker';
import fs from '@ohos.file.fs';

// 获取应用文件路径
let context = getContext(this) as common.UIAbilityContext;
let filesDir = context.filesDir;

@Entry
@Component
export struct Index1 {
  @State message: string = 'Hello World';

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
        Button('下载')
          .onClick(async () => {
            try {
              console.log('downloadTask1 filesDir 00sg00izg3.jpg');
              //下载文件
              request.downloadFile(context, {
                url: '图片地址',
                filePath: filesDir + '/00sg00izg3.jpg'
              }).then((downloadTask: request.DownloadTask) => {
                //开启回调
                downloadTask.on('complete', () => {
                  console.info('downloadTask1 complete');
                })
              }).catch((err: BusinessError) => {
                console.error("error:", err.message);
              });
            } catch (error) {
              let err: BusinessError = error as BusinessError;
              console.error(err.message);
            }
          })
          .width('100%')
        Button('保存')
          .onClick(async () => {
            try {
              let uris: String = ""
              try {
                const photoSaveOptions = new picker.PhotoSaveOptions(); // 创建文件管理器保存选项实例
                photoSaveOptions.newFileNames =
                  ["PhotoViewPicker01.png"]; // 保存文件名(可选),方括号里的文件名自定义,每次不能重复,设备里已有这个文件的话,名字就需要改个不一样的,不然接口会报错
                const photoViewPicker = new picker.PhotoViewPicker();
                try {
                  let photoSaveResult = await photoViewPicker.save(photoSaveOptions);
                  if (photoSaveResult != undefined) {
                    uris = photoSaveResult[0];
                    console.info('photoViewPicker.save to file succeed and uris are:' + uris);
                  }
                } catch (error) {
                  let err: BusinessError = error as BusinessError;
                  console.error(`[picker] Invoke photoViewPicker.save failed, code is ${err.code}, message is ${err.message}`);
                }
              } catch (error) {
                let err: BusinessError = error as BusinessError;
                console.info("[picker] photoViewPickerSave error = " + JSON.stringify(err));
              }
              try {
                let path = getContext().filesDir + "/00sg00izg3.jpg" //需要保存的图片的路径
                console.info("1111:::" + path);
                let file = fs.openSync(path)
                let file2 = fs.openSync(uris + "", fs.OpenMode.READ_WRITE)
                fs.copyFileSync(file.fd, file2.fd)
                fs.closeSync(file)
                fs.closeSync(file2)
              } catch (error) {
                let err: BusinessError = error as BusinessError;
                console.error(`[picker] Invoke photoViewPicker.save failed, code is ${err.code}, message is ${err.message}`);
              }

            } catch (error) {
              let err: BusinessError = error as BusinessError;
              console.error(err.message);
            }
          }
          )
      }
      .height('100%')
    }
  }
}
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS 关于ohos.permission.WRITE_IMAGEVIDEO
670浏览 • 1回复 待解决
HarmonyOS 自动签名能否多人共用
213浏览 • 1回复 待解决
HarmonyOS DevEco Studio 应用自动签名无效
258浏览 • 1回复 待解决
HarmonyOS 自动签名导致appid会变化
96浏览 • 1回复 待解决