Hi to all! I am making an android app for a ready made social medial website.
Website url is: "www.MixMasala.in"
I am using webview for this site, all the functionality working accept two. As this is a social media website it has also audio and video calling option. When I use this website on regular browser such as Chrome, audio and video calling also works perfectly, but when I open this site in android web view then audio and Video calling don't work i-e interface of video and audio calling options open but voice and video can't be heard and seen. You can check that functionality by logging in that site on a regular browser.
Guide me what I am missing. I am pasting code of Oncreate() method of my webview activity.

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mywebView = findViewById(R.id.wbvw);


        WebSettings webSettings = mywebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setPluginState(WebSettings.PluginState.ON);
        webSettings.setAllowFileAccess(true);
        webSettings.setAllowContentAccess(true);
        webSettings.setMediaPlaybackRequiresUserGesture(false);
        mywebView.getSettings().setLoadWithOverviewMode(true);
        mywebView.getSettings().setUseWideViewPort(true);
        mywebView.getSettings().setDomStorageEnabled(true);
          if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ) {

                    CookieManager cookieManager = CookieManager.getInstance();

                    cookieManager.setAcceptThirdPartyCookies(  mywebView , true );

                }
        mywebView.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);




                if (ContextCompat.checkSelfPermission(MainActivity.this,
                        Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED
                ) {

                    ActivityCompat.requestPermissions(MainActivity.this,
                            new String[]{Manifest.permission.RECORD_AUDIO},
                            REQUEST_RECORD_AUDIO);


                }

            }
        });


        if (savedInstanceState == null) {
            mywebView.loadUrl("https://mixmasala.in/Script");
        }




        mywebView.setDownloadListener(new DownloadListener() {
            public void onDownloadStart(String url, String userAgent,
                                        String contentDisposition, String mimetype,
                                        long contentLength) {
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i);
            }
        });

}

Dani AI

Generated

Short summary and practical fix notes for (and follow-up on ): the WebView will not grant camera/microphone access automatically. Two mistakes are common in this thread: only asking for RECORD_AUDIO at runtime (no CAMERA), and not handling the WebView permission callback. WebView-based pages that call getUserMedia trigger a WebChromeClient PermissionRequest; if onPermissionRequest is not overridden the request is denied. (developer.android.com)

Minimal pattern (handle WebView request + Android runtime permissions). Save pending PermissionRequest, ask app-level CAMERA/RECORD_AUDIO permissions if missing, then call grant(...) on the original PermissionRequest when the user approves. Example pattern:

private static final int REQUEST_MEDIA_PERMISSIONS = 1001;
private PermissionRequest pendingRequest;

myWebView.setWebChromeClient(new WebChromeClient() {
  @Override
  public void onPermissionRequest(final PermissionRequest request) {
    String[] resources = request.getResources();
    boolean needCamera = false, needAudio = false;
    for (String r : resources) {
      if (PermissionRequest.RESOURCE_VIDEO_CAPTURE.equals(r)) needCamera = true;
      if (PermissionRequest.RESOURCE_AUDIO_CAPTURE.equals(r)) needAudio = true;
    }
    if ((needCamera && ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED)
     || (needAudio && ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED)) {
      pendingRequest = request;
      ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO}, REQUEST_MEDIA_PERMISSIONS);
    } else {
      request.grant(resources);
    }
  }
});

@Override
public void onRequestPermissionsResult(int req, String[] perms, int[] results) {
  if (req == REQUEST_MEDIA_PERMISSIONS && pendingRequest != null) {
    boolean ok = true; for (int r : results) if (r != PackageManager.PERMISSION_GRANTED) ok = false;
    if (ok) pendingRequest.grant(pendingRequest.getResources()); else pendingRequest.deny();
    pendingRequest = null;
  }
}

Do not blindly grant every resource from PermissionRequest; check origin and grant only needed resources. (developer.android.com)

Troubleshooting checklist: enable WebView remote debugging (WebView.setWebContentsDebuggingEnabled(true) + chrome://inspect) to see console/getUserMedia errors; ensure hardware acceleration is not disabled for the WebView; test with a simple getUserMedia page (webrtc samples) to isolate site vs WebView; and try updating or switching the device WebView provider / Android System WebView (some Chromium WebView builds have had getUserMedia regressions). ’s point about device/OS bugs is valid — updating or changing the WebView provider often resolves platform-level problems. (developer.chrome.com)

References: WebChromeClient/onPermissionRequest docs, Android runtime-permissions guide, PermissionRequest security note, remote WebView debugging, and WebView prerelease/provider notes. (developer.android.com)

Recommended Answers

All 3 Replies

This can be related to what Android and such is running on the phone. Google the following to find the discussion.

This is definitely a bug in the Android System WebView. I'm experiencing this issue on a Galaxy S8 with Android Pie using Android WebView version 73.0.3683.90. I rolled back to version 71.0.3578.99 and this problem goes away. – Pete Apr 11 '19 at 23:43

Not all phones have this issue. I posit that you can't fix this for every phone that fails unless you create your own system.

rProfitt thanks for reply. I have tested my webview app on Huwaei honor 8 (Android Nougat) and Oppo Phones, but audio and video calling feature doesn't working . Can you tell me how to downgrade or change the version of webview? I can try this thing ,May it can solve my problem.

. Sorry but no. I don't hack Android that much but do know forums that dig into that. My best finds about such was at XDA Forum which also found another ROM (where the OS is) that saved a few phones from early retirement.

In closing, my find on this points to issues with the phone OS and not necessarily with your code as it stands.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.