使用webview web API MediaDevices.getUserMedia()无法使用。

使用webview web API MediaDevices.getUserMedia()无法使用。

HarmonyOS
2024-06-05 21:33:02
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
truemichael

参考案例:

// xxx.ets 
import web_webview from '@ohos.web.webview' 
import abilityAccessCtrl, { PermissionRequestResult, Permissions } from '@ohos.abilityAccessCtrl'; 
 
@Entry 
@Component 
struct WebComponent { 
  controller: web_webview.WebviewController = new web_webview.WebviewController() 
 
  aboutToAppear() { 
    // 配置Web开启调试模式 
    web_webview.WebviewController.setWebDebuggingAccess(true); 
    let atManager = abilityAccessCtrl.createAtManager(); 
    atManager.requestPermissionsFromUser(getContext(this), ['ohos.permission.CAMERA', 'ohos.permission.MICROPHONE']) 
    .then(data => { 
      let result: Array<number> = data.authResults; 
      let hasPermissions1 = true; 
      result.forEach(item => { 
        if(item === -1) { 
          hasPermissions1 = false; 
        } 
      }) 
      if (hasPermissions1) { 
        console.info(" hasPermissions1") 
      } else { 
        console.info(" not hasPermissions1") 
      } 
    }).catch(() => { 
      return; 
    }); 
  } 
  build() { 
    Column() { 
      Web({ src: 'https://www.bchrt.com/tools/webcam-test/', controller: this.controller }) 
        .onPermissionRequest((event) => { 
        if (event) { 
          AlertDialog.show({ 
            title: 'title', 
            message: 'text', 
            primaryButton: { 
              value: 'deny', 
              action: () => { 
                event.request.deny() 
              } 
            }, 
            secondaryButton: { 
              value: 'onConfirm', 
              action: () => { 
                event.request.grant(event.request.getAccessibleResource()) 
 
              } 
            }, 
            cancel: () => { 
              event.request.deny() 
            } 
          }) 
        } 
      }) 
    } 
  } 
}
  • 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.
分享
微博
QQ
微信
回复
2024-06-06 21:59:04
相关问题
JS APIweb组件 怎么使用
6025浏览 • 1回复 待解决
使用web无法打开HarmonyOS网址
972浏览 • 1回复 待解决
使用Devtools调试webview
847浏览 • 1回复 待解决
HarmonyOS 使用Webview会闪退
589浏览 • 1回复 待解决
HarmonyOS WebView截图API
563浏览 • 1回复 待解决
HarmonyOS web使用隐私模式
1106浏览 • 1回复 待解决
HarmonyOS hdc无法使用
957浏览 • 1回复 待解决
Image无法使用bindContextMenu
2189浏览 • 1回复 待解决
HarmonyOS TextEncoder无法使用
491浏览 • 1回复 待解决
HarmonyOS web组件的使用
1389浏览 • 1回复 待解决
创建的JS项目如何使用webview
5120浏览 • 1回复 待解决
web组件之cookie的使用
1967浏览 • 1回复 待解决