Skip to content

[firebase_dynamic_links] Clicking link leads to Play Store when browser is not open in the background even with app installed #2399

@brunomoschetta

Description

@brunomoschetta

Describe the bug
I am trying to create firebase dynamic links that will redirect users to a specific page in my app. I managed to create the link and it works sometimes, but sometimes it will re-direct to the PlayStore even with the app installed. I am doing this in a physical Android device.

What I managed to understand is that if my browser app (Chrome) is open on the background of the device when I click the link (that is in an SMS or WhatsApp message) I am taken to the app (the behavior I want). It works consistently in this setup (different links, with my app open and closed in the background). However, if I click the link and the browser app is not open in the background, it takes me to the PlayStore.

Relevant code
Here is the code I have to create the link:

Future<void> _createDynamicLink(bool short) async {
    final DynamicLinkParameters parameters = DynamicLinkParameters(
      uriPrefix: 'https://<myappname>.page.link',
      link: Uri.parse('https://<myappname>/?gameCode=1111111'),
      androidParameters: AndroidParameters(
        packageName: '<com.last.myquarentineproject>',
        minimumVersion: 0,
      ),
      dynamicLinkParametersOptions: DynamicLinkParametersOptions(
        shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
      ),
      socialMetaTagParameters: SocialMetaTagParameters(
        title: 'Example Title',
        description: 'Example Description',
      ),
    );

    Uri url;
    if (short) {
      final ShortDynamicLink shortLink = await parameters.buildShortLink();
      url = shortLink.shortUrl;
    } else {
      url = await parameters.buildUrl();
    }
  }

And here is the code I have to read link on app startup

void initState() {
    handleDynamicLinks();
...
}

  void handleDynamicLinks() async {
    final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
    _handleDeepLink(data);

    FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData dynamicLink) async {
          _handleDeepLink(dynamicLink);
        }, onError: (OnLinkErrorException e) async {
      print('Link Failed: ${e.message}');
    });
  }

  void _handleDeepLink(PendingDynamicLinkData data) {
    final Uri deepLink = data?.link;
    if (deepLink != null) {
      receivedGameCode = deepLink.queryParameters['gameCode'];
      print('receivedGameCode: $receivedGameCode');
      print('_handleDeepLink | deeplink: $deepLink');
      Navigator.pushNamed(context, '/joingGame');

    } else { print('_handleDeepLink | deeplink: NO LINK'); }
  }

Additional context

  • I do not yet have the app on Play Store. When the link leads to the PlayStore I get a "Item not found" warning. That is fine by now. Problem is I am being directed to the PlayStore even with app installed.
  • I do not get an error when debugging, because the app doesn't even open.
  • Link example: https://strategywithabeer.page.link/CiCk
    Same behavior happened on 2 different physical devices and in the android studio emulator

Flutter doctor
Run flutter doctor and paste the output below:

[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18363.778], locale en-US)
    • Flutter version 1.12.13+hotfix.8 at C:\Users\MBAUser\Documents\Flutter\flutter\flutter
    • Framework revision 0b8abb4724 (10 weeks ago), 2020-02-11 11:44:36 -0800
    • Engine revision e1e6ced81d
    • Dart version 2.7.0


[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at C:\Users\MBAUser\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
    • All Android licenses accepted.

[√] Android Studio (version 3.6)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)

[√] Connected device (1 available)
    • sdk gphone x86 • emulator-5554 • android-x86 • Android R (API 29) (emulator)

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions