title: Unable to get Android App Link to work in an Android app written in Flutter
body: <p>I am trying to implement Moneris hosted pay page from a flutter mobile app <strong>but this question is relevant to any app that wants to implement Android App Links</strong>.  In order to redirect back from the hosted pay page, I need to implement Android App Link (haven't gotten to do iOS version yet).  Based on <a href="https://developer.android.com/training/app-links/deep-linking" rel="nofollow noreferrer">this</a> article, in order for App Links to work, one needs:</p>
  
  <ol>
  <li>Identify a redirect URL on the Moneris hosted pay page (or on the page where a redirect might take place, in case of a generic example);</li>
  <li>Modify AndroidManifest.xml to associate redirects with activities;</li>
  <li>Implement a way in Flutter to intercept App Links;</li>
  <li>Place the Digital Asset Links JSON file on the web site (same domain as redirect URL) in the .well-known folder.</li>
  </ol>
  
  <p>For #1, I have identified 2 URLs, one for approved payments (<a href="https://example.com/moneris_approved" rel="nofollow noreferrer">https://example.com/moneris_approved</a>) and one for declined payments (<a href="https://example.com/moneris_declined" rel="nofollow noreferrer">https://example.com/moneris_declined</a>).  URLs have to be in https for the whole thing to work.  Moneris can reply with a POST with XML, POST with parms or GET with parms.  Tried all three.</p>
  
  <p>For #2, I have modified AndroidManifest.xml both by hand and with help of Android Studio. Relevant pieces look like this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;application
      android:name="io.flutter.app.FlutterApplication"
      android:label="&lt;label&gt;"
      android:icon="@mipmap/ic_launcher"&gt;
      &lt;activity
          android:name=".MainActivity"
          android:launchMode="singleTop"
          android:theme="@style/LaunchTheme"
          ...              
          &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:autoVerify="true"&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="https"
                  android:host="example.com"
                  android:pathPattern="/moneris_approved" /&gt;
          &lt;/intent-filter&gt;    
          &lt;intent-filter android:autoVerify="true"&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="https"
                  android:host="example.com"
                  android:pathPattern="/moneris_declined" /&gt;
          &lt;/intent-filter&gt;    
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>For #3, I am using uni_links package which takes care of channeling incoming App Links to my app.</p>
  
  <p>For #4, I have created and uploaded the assetlinks.json file and placed in the right folder.  Included both debug and release SHA256 fingerprints.  The file looks like this:</p>
  
  <pre class="lang-json prettyprint-override"><code>[
      {
          "relation": ["delegate_permission/common.handle_all_urls"],
          "target": {
              "namespace": "android_app",
              "package_name": "com.example.&lt;name&gt;",
              "sha256_cert_fingerprints":
              ["........"]
          }
      }
  ]
  </code></pre>
  
  <p>Now, after doing all that, when Moneris redirects to provided URLs, I am seeing a 404 page coming from my hosting site.</p>
  
  <p>To verify the setup, I have:</p>
  
  <ul>
  <li>Successful tested statement file with the <a href="https://developers.google.com/digital-asset-links/tools/generator" rel="nofollow noreferrer">Statement List Generator and Tester</a>;</li>
  <li>Successfully tested digital asset link file with Google APIs (<a href="https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://example.com&amp;relation=delegate_permission/common.handle_all_urls" rel="nofollow noreferrer">https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://example.com&amp;relation=delegate_permission/common.handle_all_urls</a>)</li>
  <li>Successfully tested the URL intent using ADB shell (am start -W -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "<a href="https://example.com/moneris_approved" rel="nofollow noreferrer">https://example.com/moneris_approved</a>")</li>
  <li>Successfully checked link policies using ADB (adb shell dumpsys package d)
  <a href="https://i.stack.imgur.com/RrShD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RrShD.png" alt="enter image description here"></a></li>
  </ul>
  
  <p>At this point, I don't know how else to test it or what the problem is.  I don't think the problem is with my app but rather soemthing is not closing the loop between Moneris redirect and it coming back to my app.</p>
  
  <h1>Update 1</h1>
  
  <p>I devised a testing approach like this:</p>
  
  <ol>
  <li>Created a link-test page on my site with links mimicking redirects (i.e. same host/path as in the app's AndroidManifest.xml;</li>
  <li>Created a simple Java Android App using Android Studio.  Using App Link Assistant I updated its AndroidManifest, created intents and reacted to those coming in.  Also updated the assetlinks.json file on my website.  Tested it with the link-test page running on my emulator and everything worked as expected.  App opened up ok.</li>
  <li>Repeated #2 but this time with a Flutter app using the uni_links package.  Went throught he same steps of creating slightly different links on my link-test page, updating AndroidManifest and assetlinks.json file.  Tested it with the link-test page running on my emulator and everything worked as expected.  App opened up ok.</li>
  <li>Run the app I am working on on the emulator and put the links I am expecting to get from Moneris on my link-test page and tsted on the emulator.  Everything worked as expected.  App opened up ok.</li>
  </ol>
  
  <p>So now my question is: what is the difference between me clicking on a link on my page (HTTP GET) vs. Moneris redirecting to the same link using HTTP GET?  Me clicking on the link works.  Moneris redirect does not.</p>