llfbandit / app_links

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter.
https://pub.dev/packages/app_links
Apache License 2.0
176 stars 68 forks source link

getInitialAppLink on Android, does not work correctly. #7

Closed vasilecristian closed 2 years ago

vasilecristian commented 3 years ago

I have an app that can be started from a link on iOS and Android. When the app is minimized, i can start it with a link, and the getLatestAppLink catch the link correctly. Problem: When the app is closed (aka not minimized) on Android the getInitialAppLink does not return the link. This problem is only on Android. On iOS it works.

llfbandit commented 3 years ago

There's debug logs available in logcat adb logcat. To know if the intent has been triggered on Android you can look for 'com.llfbandit.app_links' tag.

You should see something like: handleIntent: (Action) ... handleIntent: (Data) ...

llfbandit commented 2 years ago

I'm unable to reproduce it, is it still relevant on your side?

ivanlikov commented 2 years ago

Same here, if the app is opened, them minimized, pressing a link opens it fine, but if the app is completely closed, opening it through a link just opens the app normally, without handling the link.

llfbandit commented 2 years ago

Can you provide a reproducer? I use the package for my own needs and myself or my clients don't see any issue on such scenario.

alexobviously commented 2 years ago

Same for me - if the app is completely closed then the initial link is always null. The handleIntent lines are there in adb logcat, but AppLinks doesn't seem to register it.

I'm trying to use it in this project, don't know how much use this is to you: https://github.com/alexobviously/lexicle/tree/app_links/app. See: lib/cubits/app_link_handler.dart.

By the way, I tried running your example @llfbandit but I can't get it to run on flutter 2.10.1, seems like lots of the android stuff is out of date and everything I fix breaks something else. So I wonder if something has changed in flutter/android since you last tried this that is breaking your plugin for us? It might be worth updating the example project to see if it still works as expected.

Update: After messing around with AndroidManifests for a bit, I managed to get your example to run, and it does work! However, mine still doesn't and I don't see what I'm doing differently. The only thing I can think of is that my app is using the Kotlin main activity instead of Java. Do you think that could make a difference?

Update 2: I made a fresh project with Kotlin support and copied your code across. It works as expected, so I have absolutely no idea what's wrong. Maybe a plugin conflict?

Update 3: Got it working. Turns out that the initial link has to be checked before the app widget is created. Kind of makes sense when you think about it, but it took me 10+ hours to come to this realisation, so maybe this should be documented somewhere?

llfbandit commented 2 years ago

The project has been refreshed. Re-run the example on Android emulator and it works fine.