Android intent-filter path pattern - android

I want to make intent-filter which can detect urls like this one:
http://www.example.com/?p=12345
I tried with this code:
<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="www.example.com"
android:pathPattern="/\\?p=.*"/>
</intent-filter>
But it doesn't work. Can anybody help?

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

Related

Intent filter for dynamic links is not working as expected

I have following intent filter set up for detecting links to open in our app.
<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="share.example.tv"
android:pathPrefix="/"
android:scheme="https" />
<data
android:host="example.tv"
android:pathPrefix="/u"
android:scheme="https" />
</intent-filter>
I want my app to open below 2 links
https://share.example.tv/tv34gh
https://example.tv/u/some-user-name
But my app is showing up for these links as well
https://example.tv/anything/literally-anything
If I separate both of the links in different intent-filters for same activity like below
<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="share.example.tv"
android:pathPrefix="/"
android:scheme="https" />
</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:host="example.tv"
android:pathPrefix="/u"
android:scheme="https" />
</intent-filter>
This works but I don't know why.

Android deep linking schema: match both http and https

I want my app to open on http://www.example.com and https://www.example.com.
This works:
<data
android:host="www.example.com"
android:path="/"
android:scheme="http"/>
<data
android:host="www.example.com"
android:path="/"
android:scheme="https"/>
Is it possible to catch both with one entry? I tried:
<data
android:host="www.example.com"
android:path="/"
android:scheme="http*"/>
but this catches only the http link, not the https one.
So I know how I can handle bot variants, but want to use the most concise writing possible.
This seems to do the trick for me:
<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" />
<data android:scheme="https" />
<data android:host="www.mywebsite.com" />
<data android:pathPrefix="/mypage.php" />
</intent-filter>
You can use seperate <intent-filter> for both
<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="www.example.com"
android:path="/"
android:scheme="http"/>
</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:host="www.example.com"
android:path="/"
android:scheme="https"/>
</intent-filter>

"Or" in pathpattern in Intent filter

How can I say the link has to be "https://www.example.org/kk/article/Details" or "https://www.example.org/ru/article/Details" or "https://www.example.org/en/article/Details"
Need to figure out "kk or en or ru" part in the path pattern in the code below
<intent-filter android:label="login">
<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="www.example.org"
android:pathpattern="/kk or en or ru/article/Details" />
</intent-filter>
The android:pathpattern doesn't support all those rules that normal regex does. For more information read this. The only way to do that is like this:
<intent-filter android:label="login">
<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="www.example.org" android:pathpattern="/kk/article/Details" />
<data android:scheme="https" android:host="www.example.org" android:pathpattern="/en/article/Details" />
<data android:scheme="https" android:host="www.example.org" android:pathpattern="/ru/article/Details" />
</intent-filter>
You need to define all types, i.e. you need to specify data tag for each path value.
<intent-filter android:label="login">
<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="www.example.org" />
android:pathpattern="/kk/article/Details" />
android:pathpattern="/en/article/Details" />
android:pathpattern="/ru/article/Details" />
it's a old question but maybe is useful for new user. There is a solution more simple and is:
<intent-filter android:label="login">
<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="www.example.org"
android:pathpattern="/.*/article/Details" />
</intent-filter>

Custom deeplinking scheme doesn't work in some cases

Custom deeplinking scheme doesn't work in case other data tag is added to 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="#string/deep_link_scheme" />
<data android:scheme="http" android:host="myhost" />
<data android:scheme="https" android:host="myhost" />
</intent-filter>
Moving custom theme data tag to separate intent-filter fixes the problem, but what the real problem with the first solution?
<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="myhost" />
<data android:scheme="https" android:host="myhost" />
</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="#string/deep_link_scheme" />
</intent-filter>

Correct Android intent-filter configuration to associate a file type with an Activity?

This question has been asked [numerous times] before, but I have not seen any definitive answers, or examples of code that actually works.
I would like to associate an Activity with a particular file type.
For discussion, assume that I want my Activity to be associated with PDFs.
Here is what I currently have. I have experimented with many different values and combinations of values in the intent-filter, but I have yet to get my Activity to start when a PDF is selected.
<activity name="com.mycompany.MyActivity">
<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="file" />
<data android:mimeType="application/pdf" />
<data android:pathPattern="\\*\\.pdf" />
<data android:host="*" />
</intent-filter>
</activity>
Does anyone know how to actually make this work?
Have you tried with that simple version :
<activity name="com.mycompany.MyActivity">
<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:mimeType="application/pdf" />
</intent-filter>
</activity>
Your pathPattern is definitively wrong and you are restricting it too much with the mimetype.
Try the following:
<activity name="com.mycompany.MyActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.pdf" />
</intent-filter>
</activity>
To open both local and remote pdf files I'd do:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/pdf" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.pdf" />
</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:pathPattern=".*\\.pdf" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.pdf" />
</intent-filter>

Categories

Resources