2

I am building an Android app with a WebView that shows a website. On 1 page on this website, it asks the user to allow camera permission (using getUserMedia() in Javascript). When I visit this page in a normal browser (pc or mobile), it correctly shows the popup where the user can allow or deny access. However, when visiting this page through the WebView in my app, this popup is not shown at all.

For the WebViewClient, I'm using this code:

webView = findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://example.com/");

WebSettings webSettings = webView.getSettings();
webSettings.setMediaPlaybackRequiresUserGesture(false);
webSettings.setJavaScriptEnabled (true);

I've also tried using the WebChromeClient, and the popup is shown there. However the problem with that is that it opens a whole new app (the Chrome browser) and I don't think there's a way to go back to my app programatically.

I have a few solutions in mind but I don't know which one works or is possible at all:

  1. Only use WebViewClient and make it show JS popups. Is this possible?
  2. Use WebChromeClient for the page that needs camera permission, and use WebViewClient for all other pages. Problem: How do I temporarily open the camera page and go back to the app when the user clicks allow/deny?

Any advice on this? Crazy workarounds are also very much welcome.

parhine
  • 113
  • 1
  • 6
  • Based on permission inherit from chromeClient https://stackoverflow.com/questions/5271898/javascript-alert-not-working-in-android-webview. https://stackoverflow.com/questions/5329662/android-webview-geolocation – Suchith Jun 27 '23 at 10:40

0 Answers0