Open app with (deep-) link containing path and query-parameter
Asked Answered
C

1

9

These three urls are given:

1) https://example.com

2) https://example.com/app

3) https://example.com/app?param=hello

Assumed that i receive a mail in the gmail-app with these three links, I need the following behaviour:

1) Should not open the app

2) Should open the app

3) Should open the app and extract the parameter's value

What i have achieved so far:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="example.com"
            android:pathPrefix="/app"
            android:scheme="https" />
    </intent-filter>

This snippet is working fine for the cases 1) and 2): The first url is not opened in the app, the second one is. But the third link sadly i not opened by the app.

I also tried some different variations with path, pathPrefix and pathPattern, but i had no luck achieving all three given behaviours.

So I need your help guys, can you provide a snippet that meets the given requirements or some hints I can test?

Update:

Changing android:pathPrefix to android:pathPattern works now fine: The system's intent chooser is only shown for cases 2) and 3), case 1) opens the browser directly.

but

what I want to achieve additionally is to check for a specific parameter before entering the app or triggering the intent chooser. This should only happen when the parameter param holds the value hello and not goodbye. Is this possible with some kind of regular expression inside the pathPattern-attribute?

Crawl answered 6/11, 2019 at 9:43 Comment(4)
Have you used jetpack navigation in this?Jhvh
@RjzSatvara no i haven'tCrawl
Can you share the solution please for case 3 @CrawlGow
Have you been able to find a solution for the last question posted yet?Aquilegia
P
-1

I hope this solution help you in solving the task.

Manifest.xml

Don't include android:pathPrefix="/app"in Manifest.xml

<activity android:name=".YourActivity">
        <intent-filter android:label="@string/app_name">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="http"
                  android:host="example.com"/>
        </intent-filter>
</activity>

In YourActivity.kt check the Intent data to perform further action.

Note: The code is written in Kotlin

    val action = intent.action
    val data = intent.dataString
    if (Intent.ACTION_VIEW == action && data != null) {
        if (data.equals("http://example.com")) {
            Toast.makeText(this, "contains only URL", Toast.LENGTH_SHORT).show()
        } else if (data.contains("http://example.com/") && !data.contains("?")) {
            Toast.makeText(this, "contains URL with pathPrefix", Toast.LENGTH_SHORT).show()
        } else if (data.contains("http://example.com/") && data.contains("?")) {
            Toast.makeText(this, "contains URL with data", Toast.LENGTH_SHORT).show()
        }
    } else {
        Toast.makeText(this, "Intent from Activity", Toast.LENGTH_SHORT).show()
    }
Presumptive answered 6/11, 2019 at 10:59 Comment(2)
but that means, that the app is always opened, even when when the url https://example.com is not supposed to trigger the intent chosser and display my app as an opening optionCrawl
Did you find solution?Zygotene

© 2022 - 2024 — McMap. All rights reserved.