简体   繁体   中英

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);
    }
}

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());
    }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM