Pupper
Pupper

Reputation: 2355

Launching Android intents from browser with extras

I am able to launch an Android intent in webview this way:

<a href="intent:#Intent;action=...;end">Do something</a>

But I'm struggling to replicate this for intents with the "has extras" bit. For instance, how do I turn this:

final Intent intent1 = new Intent(android.content.Intent.ACTION_SEND);
intent1.setType("text/plain");
intent1.putExtra(android.content.Intent.EXTRA_TEXT, "AAA");
startActivity(intent1);

Into a one line uri so that it has the "putExtra" part? So far I've only got as far as below and am struggling to find examples that do this.

<a href="intent:#Intent;action=android.content.Intent.ACTION_SEND;type=text/plain;end">Send something</a>

Thanks in advance

Upvotes: 0

Views: 86

Answers (1)

user2413972
user2413972

Reputation: 1355

The simplest solution is to add a work through JS:

Java:

    WebSettings ws = wv.getSettings();
    ws.setJavaScriptEnabled(true);
    wv.addJavascriptInterface(new Object()
    {
       @JavascriptInterface           // For API 17+
       public void performClick(String strl)
       {
          final Intent intent1 = new Intent(android.content.Intent.ACTION_SEND);
          intent1.setType("text/plain");
          intent1.putExtra(android.content.Intent.EXTRA_TEXT, strl);
          startActivity(intent1);
       }
    }, "ok");

HTML:

<button type="button" value="someValue" onclick="ok.performClick(this.value);">OK</button>

More details and examples here: http://developer.android.com/guide/webapps/webview.html#BindingJavaScript

Upvotes: 1

Related Questions