Webview string not working

Hi
I opened developer tools on your website and the console showed this error:
image
image
Maybe this is why app inventor is not able to communicate?
This website can help you I think:

http://net-informations.com/js/iq/unerror.htm

window.AppInventor.setWebViewString() & window.AppInventor.getWebViewString()

will only work inside an AI2 app, they will not work in a PC / Computer browser - where their use will break the script.

No, I just said that for fun

Of course I am sure, tested with Android 11 device in companion mode

1 Like

Working :+1:

(in CustomWebView too)

@Oye_Lucky I got a great idea after I took a shower :star_struck:

First, try to use this code

<!DOCTYPE html>
<html>
<body onload="getLocation()">

<script>

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
  } else { 
    window.AppInventor.setWebViewString("Geolocation is not supported.");
  }
}

function showPosition(position) {
  window.AppInventor.setWebViewString("Latitude: " + position.coords.latitude + 
  "<br>Longitude: " + position.coords.longitude);
}

</script>

</body>
</html>

Second, use my edited project

test_webview_string.aia (2.1 KB)


If my solution helped you, please close this topic by clicking the solution button. Thank you :kissing_heart:

1 Like