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.
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