title: How to call an Android activity from a HTML page?
body: <p>This URL shows the snapshot of an emulator where I am showing my map in a web view. In that map When I click on Canvas link I want to call an Android activity from this HTML page given below. </p>
  
  <p><strong>Here is the HTML code</strong> </p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html
      xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta
      http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
  
  &lt;title&gt;How to parse XML and load data into HTML page&lt;/title&gt;
  
  &lt;link rel="stylesheet"
      href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" /&gt; &lt;script
      src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"&gt;&lt;/script&gt;
  
      &lt;div id="map" class="dark" style="height:250px;"&gt;&lt;/div&gt; 
      &lt;div id="latitude"&gt;&lt;/div&gt; &lt;div id="longitude"&gt;&lt;/div&gt; 
      &lt;script type="text/javascript"&gt; 
          function loadXMLDoc(XMLname) {    
              var xmlDoc;
            if (window.XMLHttpRequest) { 
                  xmlDoc=new  window.XMLHttpRequest();
                  xmlDoc.open("GET",XMLname,false);    
                  xmlDoc.send("");
                  return xmlDoc.responseXML;
              }   // IE 5 and IE 6
            else if (ActiveXObject("Microsoft.XMLDOM")) {
                  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
                  xmlDoc.async=false; 
                  xmlDoc.load(XMLname);
                return xmlDoc;    
              }   
  
              alert("Error loading  document!");  
              return null; 
          }    
      &lt;/script&gt;
      &lt;body&gt;    
          &lt;script type="text/javascript"&gt;    
               xmlDoc=loadXMLDoc("AddressDetails.xml");   
               var M = xmlDoc.getElementsByTagName("task"); 
               var i; 
               for (i=0;i&lt;M.length;i++){
                   var a = xmlDoc.getElementsByTagName("latitude")[i].childNodes[0].nodeValue;
                   var b = xmlDoc.getElementsByTagName("logitude")[i].childNodes[0].nodeValue;  
                   var map = L.map('map').setView([a,b],13); break; 
               }
  
               for (i=0;i&lt;M.length;i++) {
                   document.write("&lt;div style='width:450px;'&gt;")
                   document.write("&lt;h2&gt;"+xmlDoc.getElementsByTagName("id")[i].childNodes[0].nodeValue+"&lt;/h2&gt;");
                   document.write("&lt;p&gt;"+xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue+"&lt;/p&gt;");
                   document.write("&lt;p&gt;"+xmlDoc.getElementsByTagName("address")[i].childNodes[0].nodeValue+"&lt;/p&gt;");
                   document.write("&lt;p&gt;"+xmlDoc.getElementsByTagName("mobile")[i].childNodes[0].nodeValue+"&lt;/p&gt;");
                   document.write("&lt;p&gt;"+xmlDoc.getElementsByTagName("assignwork")[i].childNodes[0].nodeValue+"&lt;/p&gt;");
                   document.write("&lt;p&gt;Latitude&lt;span&gt;:&lt;/span&gt;"+xmlDoc.getElementsByTagName("latitude")[i].childNodes[0].nodeValue+"&lt;/p&gt;");
                   document.write("&lt;p&gt;Longitude&lt;span&gt;:&lt;/span&gt;"+xmlDoc.getElementsByTagName("logitude")[i].childNodes[0].nodeValue+"&lt;/p&gt;");
                   document.write("&lt;/div&gt;")
  
                   var userName = xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;   
                   var a = xmlDoc.getElementsByTagName("latitude")[i].childNodes[0].nodeValue; 
                   var b = xmlDoc.getElementsByTagName("logitude")[i].childNodes[0].nodeValue;
                   var assignwork = xmlDoc.getElementsByTagName("assignwork")[i].childNodes[0].nodeValue;
                   var userid = i;
                   alert(userName);
  
                   L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png',
                   {
                       attribution: '&amp;copy; &lt;a href="http://osm.org/copyright"&gt;OpenStreetMap&lt;/a&gt; contributors'
                   }).addTo(map);
  
                   // add a marker in the given location, attach some  popup content to it and open the popup   
                  L.marker([a,b]).addTo(map)
                      .bindPopup('&lt;a href="http://www.google.com"&gt;&lt;/b&gt;Get Direction&lt;/b&gt;&lt;/a&gt;&lt;br/&gt;&lt;a 
                  href="http://www.google.com"&gt;Status&lt;/a&gt;&lt;br/&gt;&lt;a id="issueID'+userid+'" 
                  href="#" onClick="setHtml(this.id)"&gt;Canvas&lt;/a&gt;').openPopup();
                  var circle = L.circle([a,b], 500, {
                      color: 'red',
                      fillColor: '#f03',
                     fillOpacity: 0.5 
                  }).addTo(map);
              }
              map.addLayer(marker);
  
              function setHtml(str) { 
                  alert(str);   
                  var HTML = str;  
                  window.HTMLOUT.showHTML(HTML); 
              }  
          &lt;/script&gt;
      &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Activity class</strong></p>
  
  <pre><code>   package com.locationTracker.periscope;
  
  import android.annotation.SuppressLint;
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.StrictMode;
  import android.view.View;
  import android.webkit.WebChromeClient;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.webkit.WebSettings.RenderPriority;
  import android.widget.TextView;
  
  
  
  public class MapActivity  extends Activity {
    @SuppressLint("SetJavaScriptEnabled")
    private WebView myWebView;
    private TextView mapTextView;
    private String url ="file:///android_asset/Map.html";
  
    @SuppressLint("SetJavaScriptEnabled")
    @SuppressWarnings("deprecation")
    @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          String url = new String("file:///android_asset/Map.html");
          setContentView(R.layout.leaflet_map);
          this.setTitle("Location Map");
          // Obtain the webView by ID
  
          if (android.os.Build.VERSION.SDK_INT &gt; 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
            .permitAll().build();
        StrictMode.setThreadPolicy(policy);
      }
          MyJavaScriptInterface js =new MyJavaScriptInterface();
          initComponent();
          WebSettings webSettings = myWebView.getSettings();
          webSettings.setJavaScriptEnabled(true);
          // performance hacks!
          webSettings.setRenderPriority(RenderPriority.HIGH);
          webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
  
          // multi-touch zoom
          webSettings.setBuiltInZoomControls(true);
         /* webSettings.setDisplayZoomControls(false);*/
          myWebView.getSettings().setLoadsImagesAutomatically(true);
          myWebView.setWebChromeClient(new WebChromeClient());
          myWebView.addJavascriptInterface(js, "Android");
          myWebView.setWebViewClient(new WebViewClient());
          //myWebView.loadUrl("http://widgets.ign.com/global/wikis/wikimap.html?full=true&amp;?popup=iphone");
          myWebView.loadUrl("file:///android_asset/Map.html");
          myWebView.setWebViewClient(new WebViewClient());
  
  
      }
  
    public void initComponent(){
  
      generateId();
    }
  
    public void generateId(){
  
      myWebView = (WebView) findViewById(R.id.webView);
      mapTextView = (TextView) findViewById(R.id.leafletTV);
    }
  
  
    class MyJavaScriptInterface
    {
        @SuppressWarnings("unused")
        public void showHTML(final String html)
        {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    //MapActivity.this.mapTextView.setText(html);
                  MapActivity.this.startActivity(new Intent(MapActivity.this, CreateIssue.class));
                }
            });
        }
    }
  }
  </code></pre>