我正在使用一个webview加载一个具有视频通话功能的网址。当我尝试发起视频通话时。我得到以下错误“权限被拒绝。请刷新页面并允许访问您的摄像头和麦克风”。
如果我给予Android运行时权限CAMERA和RECORD_AUDIO。视频通话将被启动,视频也将被传输到计算机。但在移动的端,我不能查看我的视频以及接收器的视频。它只显示getDefaultVideoPoster()。
我已经尝试使用WebChromeClient和WebViewClient,但仍然没有运气。
下面是我的代码:
private WebView webView;
webView = findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSaveFormData(true);
webSettings.setSupportZoom(false);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webView.setWebViewClient(new MyWebViewClient());
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onPermissionRequest(final PermissionRequest request) {
myRequest = request;
for (String permission : request.getResources()) {
switch (permission) {
case "android.webkit.resource.AUDIO_CAPTURE": {
askForPermission(request.getOrigin().toString(), Manifest.permission.RECORD_AUDIO, MY_PERMISSIONS_REQUEST_RECORD_AUDIO);
break;
}
case Manifest.permission.RECORD_AUDIO: {
askForPermission(request.getOrigin().toString(), Manifest.permission.RECORD_AUDIO, MY_PERMISSIONS_REQUEST_RECORD_AUDIO);
break;
}
case Manifest.permission.CAMERA: {
askForPermission(request.getOrigin().toString(), Manifest.permission.CAMERA, MY_PERMISSIONS_REQUEST_CAMERA);
break;
}
}
}
}
@Nullable
@Override
public Bitmap getDefaultVideoPoster() {
Log.i(TAG, "getDefaultVideoPoster");
return drawableToBitmap(getResources().getDrawable( R.drawable.ic_temperature));
//return super.getDefaultVideoPoster();
}
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
Log.i(TAG, "onShowCustomView");
if (view instanceof FrameLayout){
FrameLayout frame = (FrameLayout) view;
if (frame.getFocusedChild() instanceof VideoView){
VideoView video = (VideoView)
frame.getFocusedChild();
frame.removeView(video);
video.start();
}
}
}
});
2条答案
按热度按时间ldfqzlk81#
上面的代码行为我工作
rsl1atfo2#
在授予Android权限后,您应该始终在从网站收到的PermissionRequest上调用 request.grant()。否则,应用程序本身可能已经获得了所需的权限,但它仍然应该授予来自网站的权限请求:https://developer.android.com/reference/android/webkit/PermissionRequest#grant(java.lang.String[])