Select to view content in your preferred language

Web Locate Me Button is Not Working on Android Webview

1594
10
Jump to solution
10-23-2024 12:26 AM
ElieRizk
Frequent Contributor

We have a web app that shows an ESRI map with a locate me button, the button is working on the web browser, but it's not working on the Android web view, also the location permission is enabled, see code below:

the error we get on the CONSOLE: INFO:CONSOLE(285)] "Error: User denied Geolocation

the location permission enabled:

requestPermissions(
    activity,
    arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION),
    1)

@SuppressLint("SetJavaScriptEnabled")
@Composable
fun LoadWebView(url: String) {
    MyTheme {
        Surface(
            modifier = Modifier.fillMaxSize(),
            color = MaterialTheme.colorScheme.background
        ) {
            Column {
               
                val state = rememberWebViewState(
                    url
                )
                val loadingState = state.loadingState
                if (loadingState is LoadingState.Loading) {
                    LinearProgressIndicator(
                        progress = loadingState.progress,
                        modifier = Modifier.fillMaxWidth()
                    )
                }
                WebView(
                    state, onCreated = {
                        it.settings.javaScriptEnabled = true
                        it.settings.allowContentAccess = true
                        it.settings.allowFileAccess = true
                        it.settings.loadWithOverviewMode = true
                        it.settings.useWideViewPort = true
                        it.settings.domStorageEnabled = true
                        it.settings.javaScriptCanOpenWindowsAutomatically=true
                        it.settings.databaseEnabled = true
                        it.settings.setSupportMultipleWindows(true)
                        it.settings.setGeolocationEnabled(true)
                        it.webChromeClient = object : WebChromeClient() {
                            override fun onGeolocationPermissionsShowPrompt(
                                origin: String,
                                callback: GeolocationPermissions.Callback
                            ) {
                                callback.invoke(origin, true, false)
                            }
                        }
                    }, modifier = Modifier.fillMaxSize()
                )
            }


        }
    }
}
 
0 Kudos
10 Replies
ElieRizk
Frequent Contributor

Thank you everyone for your support.

The issue was solved after switching from jetpack compose to normal layout.

0 Kudos