skip to Main Content

I am trying to implement deep linking in my Flutter app without using Firebase Dynamic Links. I have followed the necessary steps to enable app links using Android App Links. However, when I try to open the deep link on some Android devices, particularly on Samsung devices, the link opens in the browser (Chrome) instead of launching the app.

AndroidManifest.xml

 <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="apartment.sakany.app"
                />
            </intent-filter>

I am using the app_links Flutter package to handle deep links:

DeepLinkService Class
I am using the app_links Flutter package to handle deep links:

class DeepLinkService {
  static const String domainUrl = 'https://apartment.sakany.app';
  static Future generateDynamicLink({
    required String urlParams,
    bool withShare = true,
  }) async {
    try {
      final shortUrl = Uri.parse("$domainUrl$urlParams");
      if (withShare) {
        shareLink(shortUrl);
      } else {
        await FlutterClipboard.copy(shortUrl.toString());
        return shortUrl;
      }
    } catch (e) {
      print(e.toString());
    }
  }

  static shareLink(Uri link) async {
    await Share.share(link.toString());
  }
}

AppLinksService Class
I handle deep link navigation with the following code:

class AppLinksService {
  static String _code = '';
  static String get code => _code;
  static bool get hasCode => _code.isNotEmpty;

  static void resetCode() => _code = '';

  static final AppLinks _appLinks = AppLinks();
  static Uri? _lastProcessedLink;
  static bool fromDeepLink = false;

  static init() async {
    try {
      final Uri? initialLink = await _appLinks.getInitialLink();
      if (initialLink != null) {
        handleDeepLink(initialLink);
      }
    } catch (e) {
      print('Error handling initial app link: $e');
    }

    _appLinks.uriLinkStream.listen((Uri? link) {
      if (link != null) {
        handleDeepLink(link);
      }
    }, onError: (Object err) {
      print('Error handling app link: $err');
    });
  }

  static void handleDeepLink(Uri? link) {
    if (link != null && link != _lastProcessedLink) {
      fromDeepLink = true; // Mark the navigation as triggered by a deep link
      _lastProcessedLink = link;
      print('Received link: $link');
      WidgetsBinding.instance.addPostFrameCallback((_) async {
        Map<String, String> params = link.queryParameters;
        String receivedId = params['id'] ?? '';

        if (receivedId.isNotEmpty) {
          print('Received id: $receivedId');
          NavigationService.navigateTo(AppRouter.kAppartmentDetailsScreen, extra: receivedId).then((_) {
            fromDeepLink = false;
          });
        } else {
          print("No valid ID found in the deep link.");
        }
      });
    }
  }

  static void clearLastProcessedLink() {
    _lastProcessedLink = null;
  }
}

enter image description here

1.Why are app links not opening the app on devices?

How can I ensure the link automatically opens the app instead of the browser across all devices?

2

Answers


  1. If your app is published

    1. (For Android) Make sure you Upload the assetlinks.json file to your website. It must be accessible via https://yourdomain/.well-known/assetlinks.json

    2. (For IOS) Make sure you Upload the apple-app-site-association It must be accessible via https://yourDomain.com/.well-known/apple-app-site-association

    If you are still in development mode and using an emulator with Android 13 or above:

    1- Go to Settings > Apps > Default apps > Opening links.

    2- Select your application.

    3- Tap "+ Add link".

    4- Select "open.my.app.example.com".

    Learn more about deep link

    Also,Check this comment

    Login or Signup to reply.
  2. If it opens the browser and does not redirect, it’s likely an issue with your hosted URL, not on the device. Make sure your hosted URL has the correct association and link files for Android and iOS; this is what tells the device browsers to loop for apps and redirect them from the website.

    Here are the Flutter docs with a video on how to implement deep linking

    Steps:

    1. Make sure your app files and permissions are correctly set up for android for iOS
    2. Ensure your hosted URL has the correct assetlint.json and apple-app-site-association files for Android and iOS, respectively. You can see how to configure those files in the Flutter deep linking tutorial video.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search