2

I'm writing an Android app that accompanies a website and I wanted to make the app intercept certain URLs. I found multiple examples through Google and on SO but none of them work. I create my Intent:

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://xgn.nl/article/" + String.valueOf(id))); 

and then launch it from another Activity (where i is the intent from above)

startActivity(i); 

The intent filter for the activity that should receive this is:

<activity android:name=".ArticleActivity" android:theme="@style/XGN.Red"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:scheme="http" android:host="xgn.nl" android:pathPrefix="/article/" android:mimeType="text/*" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity> 

I also tried it without the mimeType in the filter. The intent resolver sees the filter but complains that the data does not match with the data in the intent and launches the browser instead.

What am I doing wrong?

4
  • Could you please post the error you're getting? I'm referring to this: "The intent resolver sees the filter but complains that the data does not match with the data in the intent". Commented Oct 26, 2011 at 12:54
  • Sorry, I went back for some more debugging and actually found it :) You can turn on IntentResolver debug output through a flag and that showed me in logcat that it thought the data did not match Commented Oct 26, 2011 at 12:56
  • It should be android:pathPrefix="article", but I dont know if this is the problem... Commented Oct 26, 2011 at 12:58
  • So, you've fixed it? That's great! :) Commented Oct 26, 2011 at 12:58

1 Answer 1

4

I actually solved it 5s after I posted it, the problem was that you need to specify the fully qualified class name for this to work :)

<activity android:name="nl.xgn.ArticleActivity" android:theme="@style/XGN.Red"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <data android:scheme="http" android:host="xgn.nl" android:pathPrefix="/article/" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity> 

EDIT: To be more precise, the error I was seeing in logcat was wrong. The data type did match, but it chose the more visible browser class over my lazily defined activity. Specifying the full class name and removing the mimeType made this work.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.