aim
aim

Reputation: 21

how to allow microphone webview

i wanted to use third party callback url link(https://app.toky.co/LetsReadQuran) in android app using webview load url.
when we open the link in the browser it will ask about the allow microphone permission then proceed the call. but when we are trying to open in app. link open but do not allow microphone to call.

here is the mainactivity.java code

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {
    private WebView myWebView;
    private AdView mAdView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        myWebView = (WebView)findViewById(R.id.webview);
        WebSettings webSettings = myWebView.getSettings();
        myWebView.getSettings().setAllowFileAccessFromFileURLs(true);
        myWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
        webSettings.setJavaScriptEnabled(true);
        myWebView.loadUrl("https://app.toky.co/LetsReadQuran");
        myWebView.setWebViewClient(new WebViewClient());
        mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
    }
}

Upvotes: 1

Views: 3600

Answers (1)

Infuzion
Infuzion

Reputation: 661

To allow permissions to the microphone, you need to set the webview implementation to a custom WebChromeClient using WebView#setWebViewClient:

WebView webView = ...;
webView.setWebChromeClient(new WebChromeClient(){
    @Override
    public void onPermissionRequest(PermissionRequest request){
        // Generally you want to check which permissions you are granting
        request.grant(request.getResources());
    }
})

Upvotes: 2

Related Questions