Search code examples
androidflutterdartdeep-linkingfirebase-dynamic-links

Opening web url content in Flutter app using Firebase Dynamic Links


I've successfully setup Firebase Dynamic links for our Flutter app (only available Android so far) and it's working for the following scenarios :

  1. Generate dynamic link from app to share content among users
  2. Shared content can be opened from the app (or user will be take to Play store if app is not installed)
  3. If the dynamic link generated from the app is opened in a desktop web browser, the user will be taken to the same content available on our website (via fallback url I've setup when generating the dynamic link)

The scenario that I want implement is :

If a user shared a url from my website to a user that already has our app installed, how do I open the content directly on the app without the user taken to the web content from the device's web browser.

for example :

When a web url like this is sent to a user, when the user clicks on it from a mobile device it should open in our app instead of loading it in the mobile web browser.

https://mywebsite.com/profile/public/00352467

How do I go about making this functionality work?

I did not find any info regarding this in Dynamic Links docs.

Currently we're testing this feature using the .page.link default domain given by Firebase, hoping to connect our custom domain so that the shared URLs would look better to the users.


Solution

  • From the Flutter Deep Linking documentation, for Android, you need to:

    Add a metadata tag and intent filter to AndroidManifest.xml inside the tag with the ".MainActivity" name

    So using the example url you gave, https://mywebsite.com/profile/public/00352467, your intent filter will look like this:

    <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https" android:host="mywebsite.com" />
    </intent-filter>
    

    Clicking on the link https://mywebsite.com/profile/public/00352467 will open up the app.

    And in order to get the uri that opened the app, you can use the uni_links package like this:

    • Import the package

      import 'package:uni_links/uni_links.dart' as UniLinks;
      
    • Get the initial Uri

      Uri initialUri = await UniLinks.getInitialUri();