HarmonyOS 安全控件无法在弹窗中使用

代码如下:

安全控件放在页面里能拿到权限,放在弹窗里就不行:

长按顶部图片,调起弹窗,点击保存图片(安全控件),申请权限失败

单击底部保存图片(安全控件)按钮,申请权限成功。

import { promptAction } from '@kit.ArkUI'; 
import { common } from '@kit.AbilityKit'; 
 
@Entry 
@Component 
struct TestPage { 
  controller: TextController = new TextController(); 
  options: TextOptions = { controller: this.controller }; 
 
  build() { 
    Row() { 
      Column({ space: 10 }) { 
        Image($r('app.media.app_icon')) 
          .height(200) 
          .width('100%') 
          .objectFit(ImageFit.Contain) 
          .draggable(false) 
          .gesture( 
            LongPressGesture({ repeat: false }) 
              .onAction(() => { 
                this.showDialog() 
              }) 
          ) 
 
        SaveButton({ 
          text: SaveDescription.SAVE_IMAGE, 
          buttonType: ButtonType.Normal 
        }).onClick(async (event: ClickEvent, result: SaveButtonOnClickResult) => { 
          if (result === SaveButtonOnClickResult.SUCCESS) { 
            promptAction.showToast({ message: '设置权限成功!' }) 
          } else { 
            promptAction.showToast({ message: '设置权限失败!' }) 
          } 
        }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
    .backgroundColor(0xF1F3F5) 
  } 
 
  showDialog() { 
    const controller = new CustomDialogController({ 
      builder: SaveImageDialog({ 
        onSave: () => { 
          controller.close() 
        }, 
        onClose: () => { 
          controller.close() 
        } 
      }), 
      alignment: DialogAlignment.Bottom, 
      customStyle: true, 
    }) 
    controller.open() 
  } 
} 
 
@CustomDialog 
export struct SaveImageDialog { 
  private controller?: CustomDialogController; 
  onSave?: () => void; 
  onClose?: () => void; 
 
  build() { 
    Column() { 
      SaveButton({ 
        text: SaveDescription.SAVE_IMAGE, 
        buttonType: ButtonType.Normal 
      }).fontColor(Color.Black).fontSize(16) 
        .backgroundColor(Color.Transparent) 
        .width('100%') 
        .padding(15) 
        .onClick(async (event: ClickEvent, result: SaveButtonOnClickResult) => { 
          if (result === SaveButtonOnClickResult.SUCCESS) { 
            const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; 
            this.onSave?.() 
          } else { 
            promptAction.showToast({ message: '设置权限失败!' }) 
          } 
        }) 
 
      Line() 
        .width('100%').height(0.5) 
        .backgroundColor(Color.Black) 
 
      Text('取消') 
        .fontColor(Color.Black).fontSize(16) 
        .textAlign(TextAlign.Center) 
        .width('100%') 
        .padding(15) 
        .onClick(() => { 
          this.onClose?.() 
        }) 
    }.backgroundColor(Color.White) 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
HarmonyOS
2024-08-03 13:35:54
1267浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
jmzgh

安全控件不能放到屏幕边缘,如果超出屏幕范围一点也会失败。建议使用该组件的时候,先获取屏幕宽度,再设置具体的数值。

分享
微博
QQ
微信
回复
2024-08-04 13:48:28
相关问题
HarmonyOS 安全控件使用
627浏览 • 1回复 待解决
HarmonyOS 安全控件使用问题
1002浏览 • 1回复 待解决
HarmonyOS 依赖library中使用worker报错
1368浏览 • 1回复 待解决
image组件中使用bindContextMenu报错
1402浏览 • 1回复 待解决
HarmonyOS OAID弹窗无法展示
439浏览 • 1回复 待解决