14

I want to set up an intent filter to handle urls like: http://mysite.com/?action=delete&id=30492

I've tried setting up my intent-filter as follows:

<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="mysite.com" android:pathPrefix="/?action="/>
</intent-filter>

However, this doesn't work, and my app is not recognized as being able to handle the URL. I know that it's because I'm doing something wrong with my pathPrefix because when I remove the pathPrefix it works. I also know that it's related to having the question mark in there because if I remove the question mark from the URL and the pathPrefix, it works.

Do I need to escape the question mark in some way? I tried escaping with a slash (android:pathPrefix="/\?action=") but that doesn't work either.

How can I get this intent filter to work?

sarnold
  • 102,305
  • 22
  • 181
  • 238
Rico Yao
  • 971
  • 7
  • 9

3 Answers3

13

The query string (?action=... in your example) is not part of the path. AFAIK, you cannot filter on query strings.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
3

Since Api 19 you can use sspPattern:

android:sppPrefix="//mysite.com/?action="

Do not forget remove android:host and android:pathPrefix

Orgazm pionerki
  • 336
  • 4
  • 11
1

As mentioned by @orgazm-pionerki android:ssp seems to fix this issue. I lot couple of hours today. With a link that look like https://mywebsite.com/?param1=value1&param2=value2 I had to set this data in manifest :

<data android:scheme="https" />
<data android:host="mywebsite.com" />
<data android:sspPattern="/?param1=.*&amp;param2=.*" />
Benjamin
  • 2,777
  • 2
  • 16
  • 14