Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android https app links (deep links) don't work if app isn't already running #22336

Open
pengalo opened this issue May 10, 2024 · 8 comments
Open
Labels
area-core-platform Integration with platforms platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@pengalo
Copy link

pengalo commented May 10, 2024

Description

After creating an app link, it works great if the app is already running in the emulator or on the device. However, if the app isn't already running, it starts the app, but then immediately exits without executing the app link activity.

Steps to Reproduce

Use the excellent sample from Redth called "MAUI.AppLinks.Sample" (following this is what finally got anything working at all for my app links).
Run the application against an Android emulator or physical device (release or debug build).
Use the suggested adb command to test: adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://redth.dev/items/1234"
Observe that the app pops up an alert showing the URL that it received
Close the application in the simulator or on the device
Run the same adb command again
Observe that the app will flash the home page but then immediately exit

The exact same thing is happening with my application too. There doesn't seem to be any useful information in the Android Device Log and I've put try/catch and Debug.WriteLine files all over in my code and it just seems to die without any error listed.

Link to public reproduction project repository

https://github.com/Redth/MAUI.AppLinks.Sample

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 13, Android 14

Did you find any workaround?

No

Relevant log output

No response

@pengalo pengalo added the t/bug Something isn't working label May 10, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@PureWeen
Copy link
Member

Can you test with the latest nightly build?
https://github.com/dotnet/maui/wiki/Nightly-Builds

The latest nightly build should include a better exception about how you can resolve your scenario

@PureWeen PureWeen added the s/needs-info Issue needs more info from the author label May 10, 2024
@pengalo
Copy link
Author

pengalo commented May 10, 2024

Ok, I tried with the nightly build (8.0.40-nightly.10612), with the same behavior. Did not fix the issue of deep linking when the app isn't already running.

One note is that the adb command to use is actually: adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://redth.dev/items/1234" dev.redth.applinkssample

The previous adb command I listed (without the "dev.redth.applinkssample" at the end) actually causes the entire Android emulator to crash whether the app is running or not.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels May 10, 2024
@PureWeen
Copy link
Member

Ok, I tried with the nightly build (8.0.40-nightly.10612), with the same behavior. Did not fix the issue of deep linking when the app isn't already running.

One note is that the adb command to use is actually: adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://redth.dev/items/1234" dev.redth.applinkssample

The previous adb command I listed (without the "dev.redth.applinkssample" at the end) actually causes the entire Android emulator to crash whether the app is running or not.

Can you list out the entire exception here?

@PureWeen PureWeen added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels May 10, 2024
@pengalo
Copy link
Author

pengalo commented May 11, 2024

The adb command completes without an error, and because the app is started by running adb, not by VS, there is no exception caught or logged. I don't see any errors or anything that seems useful in the Device Log.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels May 11, 2024
@Eilon Eilon added the area-core-platform Integration with platforms label May 11, 2024
@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels May 11, 2024
@Zhanglirong-Winnie
Copy link
Collaborator

Verified this issue with Visual Studio 17.10 Preview 7.0 (8.0.21&8.0.7). Can repro on android platform with sample project.
image

@pengalo
Copy link
Author

pengalo commented May 23, 2024

I may have found a workaround. I don’t think it’s a permanent fix and I can’t be sure there aren’t unexpected side-effects, but it seems to be working for now in my project. Basically, when the app isn’t already running, it seems to get started in a state without a MainActivity, which seems to cause the problems somewhere deep in MAUI code. For the workaround, I detect if there is already a MainActivity, and if not, I start it using “Platform.CurrentActivity?.StartActivity(typeof(MainActivity))”. However, this causes the Windows array to be in a different order, so you need to use a different index to do any UI functions (such as DisplayAlert in the sample code). I haven’t figured out a way to tell which window is the correct one to use other than if the app was already running, use index [0] and if it started to handle to app link, then it is the last window in the array (in the sample, that is index[1]).

@pengalo
Copy link
Author

pengalo commented May 23, 2024

In further testing, the workaround isn't consistent. I tried adding a 250 ms delay after starting MainActivity and that helps, but it still sometimes doesn't display the deep link content (doesn't show the DisplayAlert). I'm hesitant to add a longer delay so I'm looking for another workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-platform Integration with platforms platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants