Reputation: 7893
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?
Upvotes: 4
Views: 5749
Reputation: 7893
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.
Upvotes: 4
Reputation: 434
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.
Upvotes: 0