Intent Filter to Launch My Activity when custom URI is clicked

When I was working on OAuth with Google Calendar, I had to add this filter to the Activity I wanted to receive the callback:

<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:scheme="yourapp" android:host="goog"></data>
</intent-filter>

The when the browser invoked the yourapp://goog URL, it would return to my Activity.


The final solution was a hacky workaround to cover all bases. The email now also contains an attachment with an extension that is registered to open with the app.

AndroidManifest.xml :

    <activity android:name=".gui.activity.CustomerDetailActivity" > 
        <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="https"
                 android:host="myapp.mycompany.com" /> 
        </intent-filter> 

        <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="myapp"
                 android:host="myapp.mycompany.com" /> 
        </intent-filter>

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.EDIT" />
            <action android:name="android.intent.action.PICK" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:mimeType="application/myapp" />
        </intent-filter>
    </activity>

You can get around the issue of GMail not linking non-standard protocols by using a standard HTTP URL with a 302 redirect. You could either set it up on your website's webserver or application server, or for the quick and dirty test you could use a URL shortener like http://bit.ly.