gpt4 book ai didi

java - Google meet、zoom 或 vetera 无法与 android webview 一起使用

转载 作者:行者123 更新时间:2023-12-04 11:31:58 25 4
gpt4 key购买 nike

我如何从 web View 中使用 google meet、zoom 或任何这些视频通话应用程序?
我正在尝试从我的 android 应用程序中的 webview 创建视频通话,但它显示“浏览器不兼容,请下载 chrome、firefox 或 edge”
我可以在手机的桌面模式下使用 google meet,但是当我尝试在 webview 中使用它时,它不允许我使用。
我认为问题在于 webview 没有在应用程序内使用 chrome 作为浏览器,而且我不能使用自定义选项卡,因为我需要应用程序内的视频而不是外部页面中的视频。
这是我现在的代码,它工作正常,在桌面模式下打开网址但是当我尝试启动视频时出现错误:

class CameraFragment : Fragment() {
private lateinit var binding: FragmentCameraBinding

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_camera, container, false)
}

@RequiresApi(Build.VERSION_CODES.O)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = FragmentCameraBinding.bind(view)
if (ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.RECORD_AUDIO
) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.CAMERA
) != PackageManager.PERMISSION_GRANTED){
val permissions = arrayOf(
android.Manifest.permission.RECORD_AUDIO,
android.Manifest.permission.CAMERA
)
ActivityCompat.requestPermissions(requireActivity(), permissions, 0)
}
webViewSetup()

}

@RequiresApi(Build.VERSION_CODES.O)
private fun webViewSetup() {

binding.webView.webChromeClient = object : WebChromeClientCustomPoster() {
override fun onPermissionRequest(request: PermissionRequest) {
request.grant(request.resources)
}
}

val newUA = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
binding.webView.apply {
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
settings.mediaPlaybackRequiresUserGesture = false

settings.userAgentString = newUA
loadUrl("https://www.vectera.com/login/")
}
}

override fun onResume() {
super.onResume()
requireActivity().requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
}

override fun onStop() {
super.onStop()
requireActivity().requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}


open inner class WebChromeClientCustomPoster : WebChromeClient() {
override fun getDefaultVideoPoster(): Bitmap? {
return Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
}
}


inner class MyWebViewClient : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
view.loadUrl(url)
return false
}

}

}
消息:
enter image description here

最佳答案

关于WebRtc,需要权限:

    <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

if (ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.RECORD_AUDIO
) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.CAMERA
) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.MODIFY_AUDIO_SETTINGS
) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(
requireContext(),
Manifest.permission.INTERNET
) != PackageManager.PERMISSION_GRANTED
) {
val permissions = arrayOf(
android.Manifest.permission.RECORD_AUDIO,
android.Manifest.permission.CAMERA,
android.Manifest.permission.MODIFY_AUDIO_SETTINGS,
android.Manifest.permission.INTERNET,
)
ActivityCompat.requestPermissions(requireActivity(), permissions, 0)
}

如果尝试运行,如果运行不成功,可以打开浏览器Debug模式打印出具体错误。
此外,Google 官方也有 WebRtc 的实现代码。您可以引用: here

open inner class WebChromeClientCustomPoster : WebChromeClient() {
override fun getDefaultVideoPoster(): Bitmap? {
return Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
}
override fun onPermissionRequest(request: PermissionRequest) {
activity?.runOnUiThread { request.grant(request.resources) }
}
}

设置 webChromeClient :
binding.webView.webChromeClient = WebChromeClientCustomPoster()

关于java - Google meet、zoom 或 vetera 无法与 android webview 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67590085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com