title: Call Android share intent from JavaScript in webView
body: <p>I am trying to use the code of this article to launch the share intent of my Android app (kotlin) from a JavaScript in a webView. Here is the code I use to start:</p>
  <pre><code>class MainActivity : AppCompatActivity() {  object AndroidJSInterface {
      @JavascriptInterface
      fun onClicked() {
        Log.d(&quot;HelpButton&quot;, &quot;Help button clicked&quot;)
      }
    }  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)    val webViewClient = object : WebViewClient() {
        override fun onPageFinished(view: WebView, url: String) {
          loadJs(view)
        }
      }    val webView = WebView(this)
      webView.webViewClient = webViewClient
      webView.settings.javaScriptEnabled = true
      webView.addJavascriptInterface(AndroidJSInterface, &quot;Android&quot;)    setContentView(webView)
      webView.loadUrl(&quot;https://vuetifyjs.com/en/getting-started/quick-start&quot;)
    }  private fun loadJs(webView: WebView) {
      webView.loadUrl(
        &quot;&quot;&quot;javascript:(function f() {
          var btns = document.getElementsByTagName('button');
          for (var i = 0, n = btns.length; i &lt; n; i++) {
            if (btns[i].getAttribute('aria-label') === 'Support') {
              btns[i].setAttribute('onclick', 'Android.onClicked()');
            }
          }
        })()&quot;&quot;&quot;
      )
    }
  }
  </code></pre>
  <p>I modified the function in the AndroidJSInterface like this:</p>
  <pre><code>    @JavascriptInterface
      fun shareUrl(url: String? = &quot;&quot;) {
          Log.d(&quot;JavaScript&quot;, &quot;shareUrl: &quot; + url)
          if( !url.isNullOrEmpty() )
          {
              val intent= Intent()
              intent.action=Intent.ACTION_SEND
              intent.putExtra(Intent.EXTRA_TEXT, url)
              intent.type=&quot;text/plain&quot;
              startActivity(Intent.createChooser(intent, &quot;Share To:&quot;))
          }
      }
  </code></pre>
  <p>Problem I have, is that <strong>startActivity</strong> is not recognized here (I get a &quot;Unresolved reference: startActivity&quot;). How can I access startActivity from this part of my code?</p>
  <p>Thanks for your help,</p>
  <p>Christophe</p>