Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a solution to open an activity from html.</p> <p>First your main activity containing your webview:</p> <pre><code>package com.test.jsitest; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; public class WVActivity extends Activity { private WebView m_wv = null; @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_wv); m_wv = (WebView) findViewById(R.id.webview); m_wv.getSettings().setJavaScriptEnabled(true); m_wv.loadUrl("file:///android_asset/www/index.html"); m_wv.addJavascriptInterface(new ActivityLauncher(this), "Android"); } } </code></pre> <p>Then your Javascript Interface:</p> <pre><code>package com.test.jsitest; import android.app.Activity; import android.content.Context; import android.content.Intent; public class ActivityLauncher { private Context m_context; public ActivityLauncher(Context context) { m_context = context; } public void launchActivity() { m_context.startActivity(new Intent((Activity)m_context, Activity2.class)); // Here you replace by your activity (ContactUs) } } </code></pre> <p>And finaly your html file:</p> <pre><code>&lt;DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;a href="javascript:Android.launchActivity()"&gt;Link&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I tested it and it works under a level 8 API. I hope it helps you.</p>
 

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