Home:ALL Converter>JsQRScanner in webview android not working

JsQRScanner in webview android not working

Ask Time:2021-08-18T15:02:00         Author:Sapta Ahmad Afrizal

Json Formatter

if i run in chrome, camera is working enter image description here

but if i run with webview in android studio, camera is not working enter image description here

I have enabled camera permissionenter image description here

i used JsQrScanner for scan qrcode.

MainActivity.class

    WebView webView = findViewById(R.id.web_view);
    webView.loadUrl("https://myurl");
    webView.setWebViewClient(new WebViewClient());
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setLoadWithOverviewMode(true);
    webSettings.setUseWideViewPort(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);
    webSettings.setSupportZoom(true);
    webSettings.setDefaultTextEncodingName("utf-8");

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onPermissionRequest(final PermissionRequest request) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                request.grant(request.getResources());
            }
        }

    });

AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

Author:Sapta Ahmad Afrizal,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68827837/jsqrscanner-in-webview-android-not-working
yy