title: Chrome Custom Tabs redirect to Android app will close the app
body: <p>I am trying to implement an OAuth2 flow with an Android Chrome Custom Tab but my app is always closed (no crash) when the Chrome Custom Tab is receiving the 302 with the location/scheme  of my app.</p>
  
  <p>If I create a HTML page with ahref link and touch manually on it the Chrome Custom Tab is correctly switching to my app.</p>
  
  <p>Seems like when handling the server 302 redirect in the Chrome Custom Tab it will not correctly handle my custom app scheme... but why? </p>
  
  <p>If I try the same redirect URL in a stock browser or with a WebView everything is working too.</p>
  
  <p>Here is my current setup:</p>
  
  <p>MainActiviy.java</p>
  
  <pre><code>    Button btnChromeCustomTab = (Button) findViewById(R.id.btnChromeCustomTab);
      btnChromeCustomTab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
              String packageName = CustomTabsHelper.getPackageNameToUse(MainActivity.this);
              customTabsIntent.intent.setPackage(packageName);
              Uri theLocationUri = Uri.parse(URL);
              customTabsIntent.launchUrl(MainActivity.this, theLocationUri);
          }
      });
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>    &lt;activity android:name=".MainActivity" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
  
          &lt;intent-filter android:label="@string/filter_title"&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="myappscheme" android:host="oauth" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  </code></pre>
  
  <p>This is the redirect URL that the app received with HTTP 302 code: </p>
  
  <p>myappscheme://oauth?code=1234567&amp;state=tokenCheck123</p>
  
  <p>build.gradle</p>
  
  <pre><code>android {
  compileSdkVersion 23
  buildToolsVersion "23.0.2"
  
  defaultConfig {
      applicationId "de.myapptest.webviewtest"
      minSdkVersion 16
      targetSdkVersion 23
      versionCode 1
      versionName "1.0"
  }
  
  dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.2.1'
     compile 'com.android.support:design:23.2.1'
     compile 'com.android.support:customtabs:23.0.0+'
  }
  </code></pre>
  
  <p>Thanks for any help...</p>