Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google meet, zoom or vetera not working with android webview

How could i use google meet, zoom or any of these videocall apps from a webview?

I'm trying to create video call from a webview in my android app but it says "the browser is not compatible, download chrome, firefox or edge"

I was able to use google meet in the desktop mode in my phone but when i try to use it in the webview it does not let me.

I think the problem is that webview is not using chrome as a browser inside the app and i cant use custom tabs because i need the video inside my app not in an external page.

This is my code now, which is working fine, opening the url in desktop mode but when i try to start the video the error comes up:

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
        }

    }

}

The message:

enter image description here

like image 868
MadMax Avatar asked May 18 '21 16:05

MadMax


1 Answers

About WebRtc, permissions are required:

    <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)
        }

If you try to run, if the run is unsuccessful, you can open the browser Debug mode to print out the specific error.

In addition, the official Google also has implementation code for WebRtc. You can refer to: 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) }
        }
    }

Set webChromeClient:

binding.webView.webChromeClient = WebChromeClientCustomPoster()
like image 131
Future Deep Gone Avatar answered Oct 01 '22 10:10

Future Deep Gone