安卓客户端集成了腾讯X5
h5使用如下代码请求麦克风权限:
navigator.mediaDevices
.getUserMedia({video:true,audio:true})
.then(function (stream) {
console.log('获取摄像头成功');
})
.catch(function (e) {
console.log('获取摄像头失败');
console.log(e);
});
但是安卓客户端无法收到任何回调
webView.setWebChromeClient(new WebChromeClientSafe()) public class WebChromeClientSafe extends WebChromeClient { @Override public void onPermissionRequest(PermissionRequest permissionRequest) { myRequest = permissionRequest; for (String permission : permissionRequest.getResources()) { switch (permission) { case "android.webkit.resource.AUDIO_CAPTURE": { //请求麦克风权限 askForPermission(permissionRequest.getOrigin().toString(), Manifest.permission.RECORD_AUDIO, REQUEST_RECORD_AUDIO); break; // super.onPermissionRequest(permissionRequest); public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == REQUEST_RECORD_AUDIO){ QL.d("麦克风权限回调"); if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { myRequest.grant(myRequest.getResources()); QL.d("麦克风权限回调 获取权限成功"); } else { //拒绝了 QL.d("麦克风权限回调 获取权限失败");
无法进入WebChromeClient的onPermissionRequest回调
我尝试设置了IX5WebChromeClientExtension
setWebChromeClientExtension(new IX5WebChromeClientExtension() { @Override public boolean onPermissionRequest(String origin, long l, MediaAccessPermissionsCallback mediaAccessPermissionsCallback) { QL.d("扩展 "+origin+" "+l+" "); long allowed = 0; allowed = allowed | MediaAccessPermissionsCallback.ALLOW_AUDIO_CAPTURE; boolean retain = true; mediaAccessPermissionsCallback.invoke(origin, allowed,retain); return true; });
也无法进入onPermissionRequest回调
manifese已经添加了所有相关权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />