Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't think this is the best solution to get the javascript to execute java code. See here:</p> <p>If you want to expose native code to the HTML to be callable via javascript, do the following around your web view declaration:</p> <pre><code>JavaScriptInterface jsInterface = new JavaScriptInterface(this); webView.getSettings().setJavaScriptEnabled(true); webView.addJavascriptInterface(jsInterface, "JSInterface"); </code></pre> <p>Declare the class <code>JavaScriptInterface</code>:</p> <pre><code>public class JavaScriptInterface { private Activity activity; public JavaScriptInterface(Activity activity) { this.activity = activity; } public void startVideo(String videoAddress){ Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse(videoAddress), "video/3gpp"); activity.startActivity(intent); } } </code></pre> <p>I am declaring a single function for playing a video, but you can do whatever you want.</p> <p>Finally you call this in the <code>WebView</code> contents via simple javascript call:</p> <pre><code>&lt;video width="320" height="240" controls="controls" poster='poster.gif' onclick="window.JSInterface.startVideo('file:///sdcard/test.3gp');" &gt; Your browser does not support the video tag. &lt;/video&gt; </code></pre> <p>The example is taken from another answer of mine, about playing videos, but should be explaining enough.</p> <p><strong>EDIT</strong> As per @CedricSoubrie's comment: if the target version of the application is set to 17 or higher you need to add annotation <code>@JavascriptInterface</code> above each method you want to export to the web view.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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