android magnet link data filter

1k views Asked by At

I want to launch an Android activity from my app when the user selects a magnet link in the browser.

According to the docs,

A URI is specified by separate attributes for each of its parts:
scheme://host:port/path or pathPrefix or pathPattern

The problem with magnet links is that they have a different pattern, like magnet:?xt=......

I tried something like this

<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="magnet"
        android:host="*"
    />
</intent-filter>

but it did not work (the activity didn't launch when I opened a magnet link in my browser). Could you help me in correctly declaring an intent filter for magnet links?

1

There are 1 answers

0
Gabriel On BEST ANSWER

I got this to work for me:

<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="magnet"
    />
</intent-filter>

Basically, I removed android:host