Intent filter browser android:pathPrefix url param

2019-05-12 12:02发布

问题:

So I'd like my activity to catch when an intent (browser) calls the link:

http://host/info?username=samplename 

and not when:

http://host/info?username=noname 

Here is my code coming from AndroidManifest.xml

<intent-filter>
   <action android:name="android.intent.action.VIEW"></action>
   <category android:name="android.intent.category.DEFAULT"></category>
   <category android:name="android.intent.category.BROWSABLE"></category>\
   <data android:host="host" android:pathPrefix="/info?username=samplename" android:scheme="http"></data>
</intent-filter>

I have it working for a simple prefix such as android:pathPrefix="/info" But I have problem with the character ? I tried using \? but doesn't work http://developer.android.com/guide/topics/manifest/data-element.html#path

Anybody would have any idea?

Thanks

回答1:

Have you tried \\?

Because '\' is used as an escape character when the string is read from XML (before it is parsed as a pattern), you will need to double-escape: For example, a literal '' would be written as "\" and a literal '\' would be written as "\\". This is basically the same as what you would need to write if constructing the string in Java code.