3

I want to make intent-filter which can detect urls like this one

http://x.xxxx.com/x.php?u=http%3A%2F%2Fwww.xxx.com

but i only want detect it when the url has "http%3A%2F%2Fwww.xxx.com"

does intent-filter can do this?

Edit

Here is the code i call the intent to start a url:

String url = "http://example.com/x.php?u=xxxx";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

And i tried this but it's not working:

<data android:scheme="http"  android:host="example.com" 
      android:pathPattern="/x.php?u=xxxx"/>

This also not working:

<data android:scheme="http" android:host="example.com" 
      android:pathPattern="/x.php?.*"/>

However i tried only this can working:

<data android:scheme="http" android:host="example.com" 
      android:pathPattern="/x.php"/>

I guess the problem here is that i can't contain the "?" characters in android:pathPattern However i want it can be detected only when the query string u param contain "xxxx" string.

Does it can be solve?

user3616034
  • 31
  • 1
  • 3

1 Answers1

0

You can use android:pathPattern in intent-filter in AndroidManifest. Example:

<intent-filter android:label="@string/title_app">
     <data android:pathPattern="*xxx.com*" />
</intent-filter>

Also there is another similar question here

In your case something like this

<data android:scheme="http"
      android:host="xxx.com"
      android:pathPattern="/x.php?u=http%3A%2F%2Fwww.xxx.com" />

P.S. I think, that standard applications, such as YouTube and Google+ use the same method :)

EDIT

You can't parse query parameters with intent filter, answer here

I have read documentation about Uri and it says that according to RFC 2396 path can't include "?" character

2.2. Reserved Characters

Many URI include components consisting of or delimited by, certain special characters. These characters are called "reserved", since
their usage within the URI component is limited to their reserved
purpose. If the data for a URI component would conflict with the
reserved purpose, then the conflicting data must be escaped before
forming the URI.

  reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                "$" | ","

The "reserved" syntax class above refers to those characters that are allowed within a URI, but which may not be allowed within a
particular component of the generic URI syntax; they are used as
delimiters of the components described in Section 3.

3 URI Syntactic Components

<scheme>://<authority><path>?<query>

So, I assume that pathPattern is not applied to query part.

EDIT 2

Who creates intent, that you try to catch? You or another application? May be you can send plain text intent without uri?

Community
  • 1
  • 1
Artem Mostyaev
  • 3,874
  • 10
  • 53
  • 60