'Android WebView Permissions onPermissionRequest

I seem to be having a permission based issue when displaying a chat client in a WebView in Android. Most of the chat features work properly, but the “Attach a file” button allowing a user to take or upload photos doesn’t work. I’m getting the error:

E/chromium: [ERROR:web_contents_delegate.cc(197)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.
    [ERROR:web_contents_delegate.cc(197)] WebContentsDelegate::CheckMediaAccessPermission: Not supported.

I have the following permissions defined in AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA" />

I've seen plenty of stackoverflow answers that say to add this to the webview:

myWebView.webChromeClient = object : WebChromeClient() {
    override fun onPermissionRequest(request: PermissionRequest) {
        Timber.v(request.toString())
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            request.grant(request.resources)
        }
    }
}

But the onPermissionRequest() callback never even gets called, and I'm not sure why.

I've also added a check before the webview loads:

ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)

But all of these return as PackageManager.PERMISSION_GRANTED

Does anyone have any ideas? Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source