"Or" in pathpattern in Intent filter - android

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>

Related

Android register app to open a custom extension file (also sharing it)

I am trying to let my app share and handle custom file extension and upon clicking it, it will open my app then I parse it.
I have looked into different ways like LIKE THIS for example and THIS, but clicking on the file from FileBrowser or WhatsApp for example is not detecting my app.
I am using the navigation component if it helps
I am not sure what I am doing wrong, I would appreciate it if someone have a working example.
Thanks.
This is some of the code I tried (I am testing with txt as it is an easy extension) (1)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern="*.txt" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<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/txt" />
</intent-filter>
I also tried (2)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\\.txt" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.txt"
android:scheme="file" />
</intent-filter>
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<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:scheme="content" />
<data android:mimeType="*/*" />
<!--
Work around Android's ugly primitive PatternMatcher
implementation that can't cope with finding a . early in
the path unless it's explicitly matched.
-->
<data android:host="*" />
<data android:pathPattern=".*\\.txt" />
<data android:pathPattern=".*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\..*\\.txt" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.txt" />
<!-- keep going if you need more -->
</intent-filter>
and (3)
<intent-filter
android:icon="#mipmap/ic_hp_launcher"
android:label="#string/app_name"
android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="text/plain" />
</intent-filter>
I finally my issue, I was testing multiple things at the same time.
I ended up using
<!-- this is needed for apps like whatsapp, it doesn't provide extension, so you can't add path -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data
android:mimeType="application/octet-stream"
android:scheme="content" />
</intent-filter>
<!-- this is needed for apps like explorer -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.ext"
android:scheme="content" />
</intent-filter>
If you use mimeType="*/* then check logcat (no filter at all), search for content:// then you see what is the Android sending to your app, then modify the IntentFilter to match what you want. Some apps don't send the extension so using pathPattern was not working with it, Also using schema = content is needed
Thanks #CommonsWare for the help.

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.

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>

Android intent-filter path pattern

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>

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