tags:

views:

557

answers:

1

I'm trying to catch an Android Market search intent.

That's the way you launch Android Market and search for an app by package name:

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:com.google.somepackage")));

Now, here's the intent filter for one of my activities:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="market" android:host="search" />
</intent-filter>

I'd expect Android to ask me which app should handle the intent which doesn't happen.
Yet, if I replace market with market1 or search with search1, in both places, my activity gets launched.
Is there a notion of "untouchable" intents or something?

TIA.

+4  A: 

That is odd indeed, and kinda goes against the whole open intent system. I know there are broadcasts that only the system can create, but I hadn't heard of such a thing for intent resolution.

Anyway, I just dumped the Market APK on my HTC Hero and checked the manifest. They're being slightly more specific in their URI-matching by adding the path:

<intent-filter android:priority="100">
    <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="market.android.com" android:path="/search" />
    <data android:scheme="market"
          android:host="search" android:path="" />
</intent-filter>

However, I tried adding this to my app, except I increased the priority value (not that I've seen that have any effect before), yet still I couldn't capture the Intent.

Hopefully someone (or the AOSP) can shed some light on the situation...

Christopher
By setting the priority like this, no third party application can intercept the intent. Only apps installed in the system partition can be granted a priority > 0.
hackbod
Ah ha! Thanks very much for the info.
Christopher
@hackbod would be nice if that could be added to the docs http://developer.android.com/guide/topics/manifest/intent-filter-element.html#priority
Mirko Nasato
Mirko: I filed a bug yesterday on the Android issue list pointing to this comment :)
Christopher
Just to add some more data on this. It appears that apps *not* on the system partition *can* define a `<receiver>` with a priority greater than 0. This causes the broadcasts to be ordered and received before the system apps. Note that I haven't tried this with an `<activity>` as mentioned in the question.
Christopher