tom84
tom84

Reputation: 401

How to Deep link from Website to android App

I have a website that is mainly used by mobile users. I want to link from the website to a separate app, which should then open on the phone (the app is already installed)

For the app, I have entered the following scheme:

 <variable name="URL_SCHEME" value="alfix_smart" />
    <variable name="DEEPLINK_SCHEME" value="https" />
    <variable name="DEEPLINK_HOST" value="domain.com" />
    <variable name="ANDROID_PATH_PREFIX" value="/" />
    <variable name="ANDROID_2_PATH_PREFIX" value="/" />
    <variable name="ANDROID_3_PATH_PREFIX" value="/" />
    <variable name="ANDROID_4_PATH_PREFIX" value="/" />
    <variable name="ANDROID_5_PATH_PREFIX" value="/" />
    <variable name="DEEPLINK_2_SCHEME" value="https" />
    <variable name="DEEPLINK_2_HOST" value="www.domain.com" />

how can I now link a button of a website to the app? What do I have to do for that? Unfortunately, I have no idea.

I hope you can help me

Upvotes: 0

Views: 12553

Answers (1)

aminography
aminography

Reputation: 22832

• If you want to handle deep linking in both Android and iOS, it is recommended to use Dynamic Links. With Dynamic Links, you treat on all platforms such as Android, iOS and web in a similar way. It seamlessly transits users from your mobile website to the equivalent content within your app. To see its usage example, refer to this and this.

• If you want to handle deep linking in Android only (and the app is already installed as you mentioned), in simplest approach (Deep Links), you can introduce your Activity as a handler of specific pattern URLs and pass the desired parameters as URL query params.

To see its usage example in details, refer to this.

In AndroidManifest.xml

<activity android:name=".YourActivity">

    <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 "https://example.com" -->
        <data android:host="example.com" />
        <data android:scheme="https" />
    </intent-filter>

    <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 "https://www.example.com" -->
        <data android:host="www.example.com" />
        <data android:scheme="https" />
    </intent-filter>

</activity>

In YourActivity.java:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Intent intent = getIntent();
    String action = intent.getAction();
    if(action.equals(Intent.ACTION_VIEW)){
        Uri data = intent.getData();
        if (data.getQueryParameter("some_param") != null && data.getQueryParameter("some_param").isNotEmpty()) {

            String param = data.getQueryParameter("some_param");
            // do what you want to do with param
        }
    }
}

Your html snippet:

<a href="https://example.com?some_param=some_value">Click Me!</a>

Upvotes: 2

Related Questions