简体   繁体   English

如何允许麦克风Webview

[英]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. 我想在Android应用中使用webview加载网址使用第三方回调网址链接( https://app.toky.co/LetsReadQuran )。
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 这是mainactivity.java代码

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实施定制WebChromeClient使用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());
    }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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