Skip to content

KinesteX SDK v 1.1.5

Compare
Choose a tag to compare
@V-m1r V-m1r released this 25 Oct 10:15
· 12 commits to main since this release

Modified permission request, moving handler to app level and adding exception handlers:

       webChromeClient = object : WebChromeClient() {
            override fun onPermissionRequest(request: PermissionRequest) {
                Log.d("KinesteX SDK", "Permission request received: ${request.resources.contentToString()}")

                try {
                    if (request.resources.contains(PermissionRequest.RESOURCE_VIDEO_CAPTURE)) {
                        // Store the request for later use
                        pendingCameraPermissionRequest = request

                        // Check current permission status
                        when {
                            ContextCompat.checkSelfPermission(
                                context,
                                Manifest.permission.CAMERA
                            ) == PackageManager.PERMISSION_GRANTED -> {
                                // If already granted, grant to WebView immediately
                                Log.d("KinesteX SDK", "Camera permission already granted, granting to WebView")
                                request.grant(request.resources)
                            }
                            (context as? Activity)?.shouldShowRequestPermissionRationale(
                                Manifest.permission.CAMERA
                            ) == true -> {
                                // Optional: Show rationale if needed
                                Log.d("KinesteX SDK", "Should show permission rationale")
                                requestCameraPermission()
                            }
                            else -> {
                                // Request permission
                                Log.d("KinesteX SDK", "Requesting camera permission")
                                requestCameraPermission()
                            }
                        }
                    } else {
                        Log.d("KinesteX SDK", "Denying non-camera permission request")
                        request.deny()
                    }
                } catch (e: Exception) {
                    Log.e("KinesteX SDK", "Error handling permission request", e)
                    request.deny()
                }
            }
        }

NOW you would need to override the onRequestPermissionResult handler to call the handlePermissionResult from within the GenericWebView class in KinesteXSDK:

// Your AppCompatActivity() where KinesteXSDK is used 
    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        webView?.handlePermissionResult(requestCode, grantResults)
    }