如何允许麦克风webview

时间:2017-09-23 22:42:32

标签: java android webview

我想使用webview加载网址在Android应用中使用第三方回调网址链接(https://app.toky.co/LetsReadQuran)。
当我们在浏览器中打开链接时,它会询问允许的麦克风权限然后继续通话。但是当我们试图在应用程序中打开时链接打开但不允许麦克风呼叫。

这里是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);
    }
}

1 个答案:

答案 0 :(得分:0)

要允许麦克风的权限,您需要使用WebChromeClient将webview实施设置为自定义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());
    }
})