0

I am using uni_links package in flutter to enable deep linking so, I can add functionality to share user profile in my app.

for this I have added this code to my AndroidManifest.xml

      <!-- Deep Links -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
            <data
            android:scheme="scheme"
            android:host="my_url" />
        </intent-filter>

        <!-- App Links -->
        <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" />
            <!-- Accepts URIs that begin with https://YOUR_HOST -->
            <data
            android:scheme="https"
            android:host="my_url" />
        </intent-filter>

also handling incoming route in main.dart file this way


  Uri? _initialURI;
  Uri? _currentURI;
  Object? _err;
  bool _initialURILinkHandled = false;
  StreamSubscription? _streamSubscription;

  Future<void> _initURIHandler() async {
    // 1
    if (!_initialURILinkHandled) {
      _initialURILinkHandled = true;
      // 2
      showSnackBar(context, 'Invoked _initURIHandler');
      try {
        // 3
        final initialURI = await getInitialUri();
        // 4
        if (initialURI != null) {
          debugPrint("Initial URI received $initialURI");
          if (!mounted) {
            return;
          }
          setState(() {
            _initialURI = initialURI;
          });
        } else {
          debugPrint("Null Initial URI received");
        }
      } on PlatformException {
        // 5
        debugPrint("Failed to receive initial uri");
      } on FormatException catch (err) {
        // 6
        if (!mounted) {
          return;
        }
        debugPrint('Malformed Initial URI received');
        setState(() => _err = err);
      }
    }
  }

  void _incomingLinkHandler() {
    // 1
    if (!kIsWeb) {
      // 2
      _streamSubscription = uriLinkStream.listen((Uri? uri) {
        if (!mounted) {
          return;
        }
        debugPrint('Received URI: $uri');
        setState(() {
          _currentURI = uri;
          _err = null;
        });
        // 3
      }, onError: (Object err) {
        if (!mounted) {
          return;
        }
        debugPrint('Error occurred: $err');
        setState(() {
          _currentURI = null;
          if (err is FormatException) {
            _err = err;
          } else {
            _err = null;
          }
        });
      });
    }
  }

  @override
  void initState() {
    super.initState();
    _initURIHandler();
    _incomingLinkHandler();
  }

  @override
  void dispose() {
    _streamSubscription?.cancel();
    super.dispose();
  }

btw I am using routemaster package to do routing in my flutter app here the routes


final loggedOutRoute = RouteMap(
  routes: {
    '/': (_) => const MaterialPage(child: OnboardingView()),
    "/phone/:lat/:long": (route) => MaterialPage(
          child: PhoneView(
              lat: double.tryParse(route.pathParameters['lat']!) ?? 0,
              long: double.tryParse(route.pathParameters['long']!) ?? 0),
        ),
    "/otp/:phoneNumber/:lat/:long": (route) => MaterialPage(
          child: OTPView(
              phoneNumber: route.pathParameters['phoneNumber']!,
              lat: double.tryParse(route.pathParameters['lat']!) ?? 0,
              long: double.tryParse(route.pathParameters['long']!) ?? 0),
        ),
    "/privacy": (_) => const MaterialPage(child: PrivacyPolicy())
  },
);

final splashRoute = RouteMap(routes: {
  '/': (_) => const MaterialPage(child: SplashScreen()),
});

final loggedInRoute = RouteMap(
  routes: {
    '/': (_) => const MaterialPage(child: HomeView()),
    '/profile': (_) => const MaterialPage(child: ProfileView()),
    '/profile/account': (_) => const MaterialPage(
          child: AccountView(),
        ),
    '/profile/help': (_) => const MaterialPage(child: HelpView()),
    '/profile/about': (_) => const MaterialPage(child: AboutView()),
    '/profile/settings': (_) => const MaterialPage(child: SettingsView()),
    '/profile/transaction': (_) => const MaterialPage(child: TransactionView()),
    '/filter/:category/:index/:lat/:long': (route) => MaterialPage(
          child: FilterView(
              category: route.pathParameters['category']!,
              index: int.parse(route.pathParameters['index']!),
              lat: double.tryParse(route.pathParameters['lat']!) ?? 0,
              long: double.tryParse(route.pathParameters['long']!) ?? 0),
        ),
    "/privacy": (_) => const MaterialPage(child: PrivacyPolicy()),
    "/payscreen/:uid": (route) =>
        MaterialPage(child: PayScreen(uid: route.pathParameters['uid']!)),
    '/success': (_) => const MaterialPage(child: SuccessScreen()),
    '/vendor/:uid': (route) =>
        MaterialPage(child: VendorScreen(uid: route.pathParameters['uid']!))
  },
);

also I have hosted assetlinks.json file to my domain name /.well-known/assetslinks.json

still getting this error when implementing the feature

PS C:\Users\abhij\OneDrive\Desktop\discountlo> adb shell am start -a android.intent.action.VIEW -d "discountlo://vendor/VM0enqBX84gQ5q87GAqlXqIgPRC3"
Starting: Intent { act=android.intent.action.VIEW dat=discountlo://vendor/... }
Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=discountlo://vendor/... flg=0x10000000 }

please help

abhi jain
  • 41
  • 1
  • 5

0 Answers0