0

I have hosted an HTML file with the following content

when I open this link in the Chrome browser in Android, I am able to access the camera.

Now in my android app, I am loading this hosted HTML file using webview for which I have enabled javascript, Camera is not opening in webview

the hosted html5 link is https://dcf04ed1-719d-4afb-ba44-4f213edfe6e7.htmlpasta.com

I have also uploaded a sample in GitHub to demonstrate this issue https://github.com/sanjeev444456/android_webview_sample

I have checked the logcat, there is no error I tried different combinations of webview settings still, it does not work

<input type="file" accept="image/*" capture="camera" />

    myWebView = findViewById(R.id.mywebview);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
    myWebView.getSettings().setDomStorageEnabled(true);
    myWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
    myWebView.getSettings().setAllowFileAccessFromFileURLs(true);
    myWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.setWebChromeClient(new WebChromeClient() {
        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override
        public void onPermissionRequest(PermissionRequest request) {
            Log.d(TAG, "onPermissionRequest" + request.toString());
            request.grant(request.getResources());
            Log.d(TAG, "GRANTED");
        }

        @Override
        public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
            Log.d(TAG, consoleMessage.message());
            return true;
        }
    });

    myWebView.loadUrl("https://dcf04ed1-719d-4afb-ba44-4f213edfe6e7.htmlpasta.com");

when I click "Choose" button in webview, it should open the camera, but nothing is happening currently

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sanjeev Kumar
  • 17
  • 2
  • 4

0 Answers0