Search code examples
androiduriandroid-manifestandroid-intent

Intent Filter to Launch My Activity when custom URI is clicked


I am trying to allow a URI to be registered to open up with my app. Like the PatternRepository on the Blackberry and the CFBundleURLName/CFBundleURLSchemes on the iPhone. How do I achieve the same results on the Android?

The system will be sending emails with the following link: myapp://myapp.mycompany.com/index/customerId/12345. The idea is that the user should be able to click on the link to open up the customer activity in the application.

I've tried numerous suggestions from other SO posts but I cannot get the OS to recognize the pattern and open my app.

On The Gmail app it looks like this: myapp://myapp.mycompany.com/index/customerId/12345. It recognizes and underlines the myapp.mycompany.com/index/customerId/12345 portion of the link and it opens it in a browser. The myapp:// part is not linkified.

The standard mail application treats the entire link as plain text.

What am I missing here?

PS: I've already looked at How to implement my very own URI scheme on Android and How to register some URL namespace (myapp://app.start/) for accessing your program by calling a URL in browser in Android OS?

The Manifest:

<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:versionCode="2"
    android:versionName="0.0.8" 
    package="com.mycompany.myapp.client.android">

    <uses-sdk 
        android:minSdkVersion="7" 
        android:targetSdkVersion="7"/>

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application 
        android:label="@string/app_name" 
        android:name="myappApplication" 
        android:icon="@drawable/ic_icon_myapp" 
        android:debuggable="true">

        <activity 
            android:label="My App" 
            android:name=".gui.activity.LoginActivity" 
            label="@string/app_name">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

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

        <activity android:name=".gui.activity.CustomerDetailActivity"/>
        <activity android:name=".gui.activity.CustomerImageViewerActivity" />
        <activity android:name=".gui.activity.CustomerListActivity" android:configChanges="orientation|keyboardHidden"/>
        <activity android:name=".gui.activity.HomeActivity" android:configChanges="orientation|keyboardHidden"/>
        <activity android:name=".gui.activity.AboutActivity" android:configChanges="orientation|keyboardHidden"/>
        <activity android:name=".gui.activity.AccountActivity" android:configChanges="orientation|keyboardHidden" />  
    </application>
</manifest>

Solution

  • 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>