Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid addJavascriptInterace, calling native function gives me a typeError
    primarykey
    data
    text
    <p>Ok guys. What I'm trying to do: I've got some backend code written in javascript (the project was originally supposed to be a web-app) and I've added a javascript interface to my android web view, and when I press a button in my ui, the javascript code does some stuff, then calls a function in my javascript interface when it is done... The code from my javascript interface:</p> <pre><code>public void onReady() { backend.loadUrl("javascript:dokus.backend.onLoginStatusChange(Bridge.onLoginStatusChange);"); backend.loadUrl("javascript:dokus.backend.onProjectsChange(Bridge.onProjectsChange);"); backend.loadUrl("javascript:dokus.backend.onLatestEntriesChange(Bridge.onLatestEntriesChange);"); } public void onLoginStatusChange (boolean loggedIn, String error) { Toast.makeText(mainActivity, "LoginStatusChange", Toast.LENGTH_SHORT).show(); } ... </code></pre> <p>I've already verified that the onReady function is called, so that's not the problem. The javascript function which calls onLoginStatusChange is this following:</p> <pre><code>function _login_callback(loggedIn, msg) { if (loggedIn) { _get_projects(); _get_latest_entries(); } console.log(_login_status_changed_callback); if (_login_status_changed_callback !== undefined) _login_status_changed_callback (loggedIn, msg); } </code></pre> <p>The error i get is this: "Line: 180, type error". That's all i get from my WebChromeView function, that prints everything from console.log() to a toast message.</p> <p>the console.log(_login_status_changed_callback) prints out the following:</p> <pre><code>function onLoginStatusChange () { [native code] } </code></pre> <p>I've verified that the correct arguments are called to the function (a bool and a string), so that shouldn't be the error either... I'm at a loss, what do i do?</p> <p>setup code for the web view:</p> <pre><code>private void setupBackend () { final DokusActivity that = this; backend = new WebView(this); BackendBridge.getInstance().initInstance(this, backend); backend.getSettings().setJavaScriptEnabled(true); backend.getSettings().setDomStorageEnabled(true); backend.addJavascriptInterface(BackendBridge.getInstance(), "Bridge"); backend.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(that, "Oh no! " + description, Toast.LENGTH_SHORT).show(); } }); backend.setWebChromeClient(new WebChromeClient() { public boolean onConsoleMessage (ConsoleMessage consoleMessage) { Toast.makeText(that, "Oh no! " + consoleMessage.lineNumber() + ": " + consoleMessage.message(), Toast.LENGTH_SHORT).show(); return false; } }); backend.loadUrl("file:///android_asset/index.html"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload