Skip to content

Commit

Permalink
Update request code
Browse files Browse the repository at this point in the history
  • Loading branch information
simond-stripe committed Nov 13, 2024
1 parent 5861d38 commit 94ca471
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import android.content.Context
import android.content.pm.PackageManager
import android.webkit.PermissionRequest
import android.webkit.WebChromeClient
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.checkSelfPermission
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
* A [WebChromeClient] that handles permission requests for the Stripe Connect WebView.
Expand All @@ -30,17 +32,19 @@ internal class StripeConnectWebChromeClient(
}

if (checkSelfPermission(context, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
request.grant(request.resources)
request.grant(arrayOf(PermissionRequest.RESOURCE_VIDEO_CAPTURE))
} else {
val scope = permissionScopeBuilder().also {
inProgressRequests[request] = it
}
scope.launch {
val granted = requestPermissionFromUser(Manifest.permission.CAMERA)
if (granted) {
request.grant(arrayOf(PermissionRequest.RESOURCE_VIDEO_CAPTURE))
} else {
request.deny()
val isGranted = requestPermissionFromUser(Manifest.permission.CAMERA)
withContext(Dispatchers.Main) {
if (isGranted) {
request.grant(arrayOf(PermissionRequest.RESOURCE_VIDEO_CAPTURE))
} else {
request.deny()
}
}
inProgressRequests.remove(request)
}
Expand Down

0 comments on commit 94ca471

Please sign in to comment.