4

I have my custom website where my android app will get data.

Lets call it example.com.

My android app can share links via other applications like WhatsApp. When link is shared, it creates link like http://example.com/my/path/to/information.

I want to open my own application when this link is clicked. In my AndroidManifest file I have added these lines of code for my intent:

<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:pathPattern="/.*" android:scheme="http"/>
</intent-filter>

My Activity handles its intent like this:

Intent intent = getIntent();
Log.d("My_intent", intent.toString());
mainNewsId = intent.getStringExtra("news_info");
Log.d("News_result", mainNewsId);

When I use other applications where link is shared and click it, it must suggest to me applications that can open this link.

However, it does not suggest my application that shared this link.

What did I miss? Do I need to add meta tags to my webpage for android?

========================UPDATE=================================

I have found an interesting outcome. In my intent filter, if I write on android:host some other popular site, which has its own android app, it suggests to open my applcation along with its own application when I click to link.

Does it mean that I need to write something in my webpage?

Mr.D
  • 7,353
  • 13
  • 60
  • 119
  • check this link http://stackoverflow.com/questions/5596261/intent-filter-to-launch-my-activity-when-custom-uri-is-clicked – Rustam Sep 14 '15 at 06:46
  • Are you mentioning any activity that should handle your intent filter? – Rustam Sep 14 '15 at 06:58
  • Yes. This intent filter is inside handling activity. Problem is when I click to link in my other app. It suggests to open it by my browsers but does not suggest my application. – Mr.D Sep 14 '15 at 07:02
  • add your code where you suggest to open the link. – Rustam Sep 14 '15 at 07:03
  • Did you try without giving the pathPattern – Giridharan Sep 14 '15 at 07:04
  • This work for me check this it will you or someone else later on http://stackoverflow.com/questions/40781149/app-link-not-working-for-facebook-on-android/40781465#40781465 – Naeem Ibrahim Nov 24 '16 at 08:55

2 Answers2

4

I have solved my problem by using these methods.

In my web page, I have added link tags to head:

<link rel="alternate" href="android-app://com.example.app/example.com/my/path/to/information"/>

In my manifest, I have added this:

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

This worked. Now when I click to links it suggests my application to open it.

Mr.D
  • 7,353
  • 13
  • 60
  • 119
0

Try providing specific path prefixes. For example if you wish to open http://example.com/my/path/to/information then intent filter should look like this

<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:pathPattern="/my/" android:scheme="http"/>

Then if you wish to open the same activity with different path prefixes, you will need to add a data tag for each prefix.

Saurabh
  • 434
  • 1
  • 4
  • 19