Android Question WebviewExtras

RUNO

Active Member
Licensed User
Longtime User
I have webpage for get location (for example)
It is work in browser but if I use webviewextras for execute javascript ,my app is crash
Can anyone help me ?
 

eps

Expert
Licensed User
Longtime User
What javascript are you executing? Some code might help.... Plus what the errors are when it crashes!!
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Please post the contents of the log window when the crash happens.
Please post the code where the crash occurs.

Please remember to post the above info in <CODE>...</CODE) tags.
 
Reactions: eps
Upvote 0

RUNO

Active Member
Licensed User
Longtime User
Thanks for all
Are you using webviewextras2 and webviewsettings? No .
The code in webpage

B4X:
<!DOCTYPE html>
<html>
<body>

<p>Please click the button</p>

<button onclick="getLocation()">Press here</button>

<p id="demo"></p>

<script>
var x = document.getElementById("demo");

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition, showError);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}

function showPosition(position) {
  x.innerHTML = "Latitude: " + position.coords.latitude +
  "<br>Longitude: " + position.coords.longitude;
}

function showError(error) {
  switch(error.code) {
    case error.PERMISSION_DENIED:
      x.innerHTML = "User denied the request for Geolocation."
      break;
    case error.POSITION_UNAVAILABLE:
      x.innerHTML = "Location information is unavailable."
      break;
    case error.TIMEOUT:
      x.innerHTML = "The request to get user location timed out."
      break;
    case error.UNKNOWN_ERROR:
      x.innerHTML = "An unknown error occurred."
      break;
  }
}
</script>

</body>
</html>


In B4A I use example with this link
for @warwound
 
Last edited:
Upvote 0

eps

Expert
Licensed User
Longtime User
Okay, so what is the error you get?

How are you instantiating the web view in B4A?

Something like ?

B4X:
Sub Globals
    Dim wv As WebView
    Dim wve As WebViewExtras
    Dim wvs As WebViewSettings
End Sub

Sub ShowWebBrowser

...

    wv.Initialize("wv")
    wve.Initialize(wv)

    Dim JavascriptInterface1 As DefaultJavascriptInterface
    JavascriptInterface1.Initialize

    Dim WebChromeClient1 As DefaultWebChromeClient
    WebChromeClient1.Initialize("WebChromeClient1")
    wve.SetWebChromeClient(WebChromeClient1)
    wve.AddJavascriptInterface(JavascriptInterface1,"Android") 'Added so that Javascript can communicate with Android App
    wvs.setAllowFileAccess(wv,True)
    wvs.setAppCacheEnabled(wv,True)
    wvs.setDOMStorageEnabled(wv,True)
    wvs.setDisplayZoomControls(wv,False)

...

End Sub

Of course your options may well be different to those above.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
You might want to consider this as well

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…