Grant special permissions to a WebView

Accessing the camera or location in a WebView is not possible without granting the WebView permission. Make sure your app has permissions already through the conventional method before calling this snippet:

WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.setWebChromeClient(new WebChromeClient() {
    // Need to accept permissions to use the camera and audio
    @Override
    public void onPermissionRequest(final PermissionRequest request) {
        Log.d(TAG, "onPermissionRequest");
        getActivity().runOnUiThread(new Runnable() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void run() {
                // Make sure the request is coming from our file
                // Warning: This check may fail for local files
                // Remove this check if your webpage is from a different
                // source
                if (request.getOrigin().toString().equals(ASSET_FILE)) {
                    request.grant(request.getResources());
                } else {
                    request.deny();
                }
            }
        });
    }
});