How to access the camera from within a Webview?

后端 未结 5 1009
滥情空心
滥情空心 2020-11-30 06:50

In my android app, I am trying to load a webpage (that must access the camera) on WebView. On my laptop, when I load the webpage, I could access the camera.

5条回答
  •  自闭症患者
    2020-11-30 07:41

    Up on meuser07's answer, here is what worked for me. Other than permission in the Manifest.xml, You need to check/grant on run time as well.

    I hope it helps.

                override fun onPermissionRequest(request: PermissionRequest) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        if (ContextCompat.checkSelfPermission(this@YourActivity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
                                                    RxPermissions(this@YourActivity).request(Manifest.permission.CAMERA).subscribe({
                                if (it) request.grant(request.resources)
                            }, {
                                Timber.e(it, "Error requesting camera")
                            }).addSubscription()
                        } else {
                            request.grant(request.resources)
                        }
                    }
                }
    

    I am using RxPermission to grant the permissions. Also, you need to add this configuration.

    webView.settings.mediaPlaybackRequiresUserGesture = false
    

提交回复
热议问题