title: How to send data from my TWA webapp to my app?
body: <p>With Crosswalk I had a very convenient javascript-to-app interface so I could <strong>call a java function from javascript and share data from my webapp to my android app</strong>.</p>
  
  <p><strong>How can I achieve this with Custom Tabs (or Trusted Web Activity) ?</strong></p>
  
  <p>There seems to be no way at all. There should be, especially when my app and my game/webapp are from the same author.</p>
  
  <p>For example, I do not trust LocalStorage, especially now with Custom Tabs, it may get cleaned, or the user may uninstall the browser and install another one, so the saved data will be lost and the user will be angry at the app for the loss of the saved data, not even understanding that the data were in the browser, not in the app. So I used to have my webapps call the app to save datas.</p>
  
  <p>Another example, when the Custom Tab uses Firefox instead of Chrome, then speech synthesis won't be available. I can detect it easily in my webapp. But I want my webapp to call the app and send it the words to pronounce. That is what I was doing with Crosswalk since it didn't support speech neither.</p>
  
  <p>I understand that webviews are more appropriate for my use than Custom Tabs, but when the webview can't be used on a device (especially Android &lt;5) then my app doesn't have a lot of other options than opening a Custom Tab instead (or Trusted Web Activity if available). I can't use Crosswalk anymore, it is discontinued and still full of serious bugs. And other solutions such as GeckoView or Alibaba Gcanvas are not ready.</p>
  
  <p>edit:</p>
  
  <p>In this article about Trusted Web Activity <a href="https://developers.google.com/web/updates/2017/10/using-twa" rel="noreferrer">https://developers.google.com/web/updates/2017/10/using-twa</a> I read</p>
  
  <blockquote>
    <p>Nevertheless, you can coordinate with the web content by passing data
    to <strong>and from</strong> the page in URLs (e.g. through query parameters, custom
    HTTP headers, and intent URIs.)</p>
  </blockquote>
  
  <p>edit:</p>
  
  <p>I've been reading many pages, Intents and deep-linking are still obscure to me though, but here is what I tried.</p>
  
  <p>I added an intent filter for a custom action :</p>
  
  <pre><code>&lt;receiver android:name=".OutgoingReceiver" android:enabled="true"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="custom_tabs_js_interface" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>I created a class for that receiver :</p>
  
  <pre><code>public class OutgoingReceiver extends BroadcastReceiver {
  
      public static final String CUSTOM_INTENT = "custom_tabs_js_interface";
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Toast.makeText(context, "received" , Toast.LENGTH_SHORT).show();
      }
  </code></pre>
  
  <p>and I call it in javascript with </p>
  
  <pre><code>location.href="intent:#Intent;action=custom_tabs_js_interface;end";
  </code></pre>
  
  <p>I don't even pass data for now, I just try to call it.
  but nothing happens...</p>