1

I am using deep linking to share my active link to different applications like WhatsApp. The problem is I want to share 2 different activities. Now I am able to share them but if we assume I will share activity A. After clicking on the link, I will see my application option well that's fine and it will take me to activity A.

But now if I do share to activity B.When I try to click on the link, my application will appear twice at one time, and if I choose what was previously chosen by activity A, it will take me to my activity A.This is a wrong choice, so the requested activity will not work.

See the pictures for clarification this is activity A:

enter image description here

And this is activity B here problem :

enter image description here

As you can see my app come at two time.

So what is the problem are there anyone know solve to this problem help me.

this is manifest code:


<!--   1-->
        <activity
            android:name=".FragmanM.MainActivityM" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </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" />

                <data
                    android:scheme="http"
                    android:host="============"
                    android:pathPrefix="/post" />
            </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" />
                <data
                    android:scheme="https"
                    android:host="==============="
                    android:pathPrefix="/post" />
            </intent-filter>
        </activity>

<!--    2   -->

        <activity
            android:name=".FragmantA.MainActivityA" >
            <intent-filter >

                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
            </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" />

                <data
                    android:scheme="http"
                    android:host="================"
                    android:pathPrefix="/posts" />
            </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" />
                <data
                    android:scheme="https"
                    android:host="==============="
                    android:pathPrefix="/posts" />
            </intent-filter>
        </activity>

this activity A


Uri data =getActivity(). getIntent().getData();

        if (data!= null) {
            try {
                post_id =  data.getLastPathSegment().toString();
                getPost(post_id);


            } catch (NumberFormatException e) {
                post_id=null;
            }



        }


        Bundle bundle = getActivity().getIntent().getExtras();
        if (bundle !=null){
            if(post_id==null){
                post_id =bundle.getString("mid");


                getPost(post_id);


            }

        }


this is activity B



Uri data =getActivity(). getIntent().getData();

        if (data!= null) {
            try {
                posts_id =  data.getLastPathSegment().toString();
                getPost(posts_id);



            } catch (NumberFormatException e) {
                posts_id=null;
            }



        }


        Bundle bundle = getActivity().getIntent().getExtras();
        if (bundle !=null){
            if(posts_id==null){
                posts_id =bundle.getString("moid");
                getPost(posts_id);


            }

        }

AgentP
  • 6,261
  • 2
  • 31
  • 52
  • Can you provide us the examples of URLs that you are having? – AgentP Jul 10 '20 at 08:10
  • Why do you have doubled intent-filters in AndroidManifest? – Mariusz Brona Jul 10 '20 at 08:24
  • Hi brother, I solved the problem of the appearance of two of the application, but now the problem is the two links take me to the same activity @AgentP –  Jul 10 '20 at 08:33
  • How can I make it one apologize I'm a new app developer @MariuszBrona –  Jul 10 '20 at 08:34
  • now the problem is the two links take me to the same activity @MariuszBrona –  Jul 10 '20 at 08:35
  • I have written methods to move users to different activities did you checked it? – AgentP Jul 10 '20 at 09:09
  • Yes I do it like that : https://a.top4top.io/p_1652abudu1.png @AgentP –  Jul 10 '20 at 09:34
  • @AgentP Hello brother. Sorry for the delay. I was doing a small sample to help explain the problem Please check the source code of the attachment, make a post from A-B and try the links to view the problem : top4top.io/downloadf-16524whlp1-rar.html –  Jul 10 '20 at 11:06

1 Answers1

0

Both of your activities are providing intent filters but the reason for this is, you are providing a similar path prefix.

What I mean by this is in your first activity i.e .FragmanM.MainActivityM you have mentioned

 <data
      android:scheme="http"
      android:host="============"
      android:pathPrefix="/post" /> 

And in .FragmantA.MainActivityA you have written this

 <data
      android:scheme="http"
      android:host="============"
      android:pathPrefix="/posts" /> 

Now take a look at the pathPrefix

By the definition and according to documentation pathPrefix :

The pathPrefix attribute specifies a partial path that is matched against only the initial part of the path in the Intent object

So when you come across links such as this: www.yourhost.com/posts the first activity also gets shown and the second one also showed which is expected.

So how to fix this?

Method 1: You can remove intent-filter from your second activity and have single activity handle both paths in this case .FragmanM.MainActivityM

and inside that activity make a check-in onCreate() somewhat like this

        Uri data = getIntent().getData();
        if(data.getPath().startsWith("/posts"))
        {
            //Start Your second activity here 
        }

Method 2: Create a whole new activity just to handle links and from there you filter links and move the user to different screens

AgentP
  • 6,261
  • 2
  • 31
  • 52
  • Actually, I didn't understand very well what to I do. Sorry, because I am a new application developer.But I have modified the code as follows. Please see the picture: https://h.top4top.io/p_1652k8qc91.png but still The links of second activity still take me to the first activity. –  Jul 10 '20 at 09:27
  • Hey, I checked this link http://marketoman.000webhostapp.com/.well-known/assetlinks.json It shows 404 errror – tadev Jul 10 '20 at 09:37
  • Hello brother. Sorry for the delay. I was doing a small sample to help explain the problem Please check the source code of the attachment, make a post from A-B and try the links to view the problem : https://top4top.io/downloadf-16524whlp1-rar.html –  Jul 10 '20 at 10:57
  • Thank you, brother. I got it now. Your answer was correct. Thank you very much –  Jul 10 '20 at 20:56