1
votes

I have created a DynamicLink programatically which includes sub-domain syntax, some title and preview Image. I have also specified the IntentFilter which should open that activity when clicked. But when the link is clicked it open another Activity which also have Deep link. page.link domain is provided by google itself in Firebase Console The code for creating Dynamic Link is

 String e="https://learnandroid.page.link/?link=https://learn.android/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";

Task<ShortDynamicLink> shortLinkTask = FirebaseDynamicLinks.getInstance()
                        .createDynamicLink()
                        .setLongLink(Uri.parse(e))
                        .buildShortDynamicLink()
                        .addOnCompleteListener(new OnCompleteListener<ShortDynamicLink>() {
                            @Override
                            public void onComplete(@NonNull Task<ShortDynamicLink> task) {
                                Uri get=task.getResult().getShortLink();
                                Intent sh=new Intent(Intent.ACTION_SEND);
                                sh.setType("text/plain");
                                sh.putExtra(Intent.EXTRA_TEXT,"Vi                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ew the Amazing Event   "+get);
                                startActivity(Intent.createChooser(sh,"View"));
                            }
                        });  

The Intent filter for Activity is given as

<activity android:name=".content.Home"
            android:launchMode="singleTask"
            android:screenOrientation="portrait">
            <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="learn.android"
                    android:scheme="https" />
            </intent-filter>
        </activity>  

But when the link generated is clicked it opens some Another activity.

2

2 Answers

1
votes

If you have deeplink in multiple activities then you should use android:pathPattern to differentiate them from each other.

Here is sample code

<data
    android:host="learn.android"
    android:pathPattern="/home"
    android:scheme="https" />

and add /home to your link

String e="https://learnandroid.page.link/?link=https://learn.android/home/&apn=com.learnandro&amv=16&st=Please view the ContentEvent&si="+some Image Url+"&afl=https://play.google.com/store/apps/details?id=app Package name";
0
votes

You can try below snippet :

     val data: Uri? = intent?.data
     if (Uri.EMPTY != data) 
     {
        val id = intent.data?.getQueryParameter("ID")    
        intent = Intent(this, ActivityName::class.java)    
        startActivity(intent)  
        finish()
     }
  • In getQueryParameter, you need to pass KEY name which contains data in URL
  • Define this set of code in Activity which is defined in Manifest file