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?

6
  • check this link stackoverflow.com/questions/5596261/… Commented Sep 14, 2015 at 6:46
  • Are you mentioning any activity that should handle your intent filter? Commented Sep 14, 2015 at 6: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. Commented Sep 14, 2015 at 7:02
  • add your code where you suggest to open the link. Commented Sep 14, 2015 at 7:03
  • Did you try without giving the pathPattern Commented Sep 14, 2015 at 7:04

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

Tried. My phone does not suggest my app to open this link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.