title: How to redirect back to Android app?
body: <p>I need to open a Custom Chrome tab that brings the user to my website, and then redirects the user back to the app. Its similar to launching a page for OAuth.</p>
  
  <p>Here is what the Android side looks like...</p>
  
  <p><strong>AndroidManifest.xml</strong> (adds intent filter to activity for listening to URI)</p>
  
  <pre><code>&lt;activity android:name=".app.MyActivity"
          android:label="@string/title"
          android:theme="@style/AppTheme"
          android:launchMode="singleTask"
          android:screenOrientation="portrait"&gt;
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.VIEW" /&gt;
              &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
              &lt;data android:scheme="mytest" /&gt;
          &lt;/intent-filter&gt;
  
      &lt;/activity&gt;
  </code></pre>
  
  <p><strong>Activity.java</strong> (launches custom chrome tab)</p>
  
  <pre><code>private void goToSite() {
      CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
      int toolbarColor = getResources().getColor(R.color.primary);
      intentBuilder.setToolbarColor(toolbarColor);vice_key(), shared().getAccessToken());
      intentBuilder.build().launchUrl(this, Uri.parse("https://example.com/some-page"));
  }
  </code></pre>
  
  <p>On my server, the user completes a form and is eventually brought to a page that is supposed to redirect them back into the app...</p>
  
  <p><strong>server.html</strong></p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;Redirecting...&lt;/title&gt;
  &lt;script&gt;
      var redirectToApp = function() {
          setTimeout(function appNotInstalled() {
              window.location.replace("http://example.com/app-not-installed");
          }, 100);
          window.location.replace("mytest://justanexample");
      };
      window.onload = redirectToApp;
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But I am not being redirected to the app. I suspect something is wrong with my server code because a similar setup (the manifest and activity code) works when dealing with OAuth pages. What is wrong with my server code? How can I troubleshoot this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The Android side appears to be correct - Changing the server code to <code>&lt;a href="mytest://other/parameters/here"&gt;GO TO APP&lt;/a&gt;</code> appears to work but I need a way that does not involve clicking a link</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>The code above actually works :/</p>
  
  <p>Because I was in a Chrome custom tab I was redirecting to the page I was already at (because the Chroms custom tab activity is considered to be in-app). This made me think no redirect was occurring. Tristan's comment helped me realize this</p>