Search code examples
androidandroid-studiodeep-linking

How do I get values from a deep link in android?


I'm implementing deep-linking in android, what I'm trying to do is when a user clicks on the link, he gets redirected on the application, and this already works, but I also want that the user can see some values I pass inside the link.

Example:

My link is: https://examplelink.com/123456789. The application needs to get 123456789 code.

How do I do this?

NB: I've alredy put this on the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sendsharedlink">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <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" />
            <!-- Accepts URIs that begin with "example://gizmos” -->
            <data android:scheme="https"
                android:host="examplelink.com" />
        </intent-filter>
    </activity>
</application>

I HAVE RESOLVED BY PUTTING:

Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();

String[] link = data.toString().split("/");

txt.setText(link[3]);

Thanks for the help.


Solution

  • The first copy this code in manifest

    <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="your host name"
                        android:pathPrefix="your path"
                        android:scheme="https" />
    
    
                </intent-filter>
    

    This is our app link: https://myapp.page.link/path?email=your@gmail.com&token=12345

    and in my splash activity i get data with kotlin code:

    Firebase.dynamicLinks
                .getDynamicLink(intent)
                .addOnSuccessListener(this) { pendingDynamicLinkData ->
                    // Get deep link from result (may be null if no link is found)
                    val data: Uri? = intent?.data
                    // get path
                    val path = data?.path
                    // get param
                    val email = data?.getQueryParameter("email").toString()
    
                }.addOnFailureListener(this) { e -> MLog.e(TAG, "getDynamicLink:onFailure $e") }