当浏览器需要摄像头或者麦克风时,都会弹出确认摄像头和麦克风权限弹框
小编最近在做webrtc的项目,用的是内嵌的X5内核的webview进行语音视频通话,但每次启动app都会弹出权限对话框,原本想在js上解决这个问题,结果是没法解决,因为这对于浏览器来说是一个安全性的问题,防止访问网页时,在不知名的情况下摄像头被打开,涉及到隐私的问题,所以只能在webview中想办法。
原生的webview在6.0以上是有具体的api可以直接去掉,小编用的webrtc在5.0以下,原生webview是无法使用的,所以只能用X5的webview,看完官方api以后,并没找到具体的方法,只能试下向官方反馈了。
说实话,官方还是很给力的,过不了多久就用QQ把解决方法发给我了
下面是官方文档的截图:
webview_calling.setWebChromeClientExtension(new IX5WebChromeClientExtension() { @Override public Object getX5WebChromeClientInstance() { return null; } @Override public View getVideoLoadingProgressView() { return null; } @Override public void onAllMetaDataFinished(IX5WebViewExtension ix5WebViewExtension, HashMap<String, String> hashMap) { } @Override public void onBackforwardFinished(int i) { } @Override public void onHitTestResultForPluginFinished(IX5WebViewExtension ix5WebViewExtension, IX5WebViewBase.HitTestResult hitTestResult, Bundle bundle) { } @Override public void onHitTestResultFinished(IX5WebViewExtension ix5WebViewExtension, IX5WebViewBase.HitTestResult hitTestResult) { } @Override public void onPromptScaleSaved(IX5WebViewExtension ix5WebViewExtension) { } @Override public void onPromptNotScalable(IX5WebViewExtension ix5WebViewExtension) { } @Override public boolean onAddFavorite(IX5WebViewExtension ix5WebViewExtension, String s, String s1, JsResult jsResult) { return false; } @Override public void onPrepareX5ReadPageDataFinished(IX5WebViewExtension ix5WebViewExtension, HashMap<String, String> hashMap) { } @Override public boolean onSavePassword(String s, String s1, String s2, boolean b, Message message) { return false; } @Override public boolean onSavePassword(ValueCallback<String> valueCallback, String s, String s1, String s2, String s3, String s4, boolean b) { return false; } @Override public void onX5ReadModeAvailableChecked(HashMap<String, String> hashMap) { } @Override public void addFlashView(View view, ViewGroup.LayoutParams layoutParams) { } @Override public void h5videoRequestFullScreen(String s) { } @Override public void h5videoExitFullScreen(String s) { } @Override public void requestFullScreenFlash() { } @Override public void exitFullScreenFlash() { } @Override public void jsRequestFullScreen() { } @Override public void jsExitFullScreen() { } @Override public void acquireWakeLock() { } @Override public void releaseWakeLock() { } @Override public Context getApplicationContex() { return null; } @Override public boolean onPageNotResponding(Runnable runnable) { return false; } @Override public Object onMiscCallBack(String s, Bundle bundle) { return null; } @Override public void openFileChooser(ValueCallback<Uri[]> valueCallback, String s, String s1) { } @Override public void onPrintPage() { } @Override public void onColorModeChanged(long l) { } @Override public boolean onPermissionRequest(String s, long l, MediaAccessPermissionsCallback mediaAccessPermissionsCallback) { long allowed = 0; allowed = allowed | MediaAccessPermissionsCallback.ALLOW_AUDIO_CAPTURE; boolean retain = true; mediaAccessPermissionsCallback.invoke(s, allowed,retain); return true; } });
在IX5WebChromeClientExtension重写方法onPermissionRequest里面实现默认允许
总感觉大家也会遇到这种问题,向大家分享下,小编这边只在5.0以下试过是没问题的,高版本的不太确定,大家可以试试