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.

  • Setting Button text font in android
  • The Facebook login doesn't work anymore since I upgraded the Firebase app to the new Console (only)
  • Why do the TabLayout's tabs' icons/texts blink when swiping between pages?
  • How to store long text in Android?
  • How to develop plugins for the native Android browser
  • What is the default transition between activities in Android 4.0 (API 14+)
  • 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>
    

    Related posts:

    Googletest for Android NDK
    Getting ClassCastException when trying to insert RelativeLayout dyanmically?
    Shared element transition don&#039;t have the expected behaviour
    How to get thumbnail for video in my /sdcard/Android/data/mypackage/files folder?
    How to add PDFBox to an Android project or suggest alternative
    How to use android support library correctly
  • Android: Want to set custom fonts for whole application not runtime
  • How to disable AutoCompleteTextView's drop-down from showing up?
  • PagerTabStrip tabs alignment to left
  • Is it possible to disable access to fragment's layout(views) from parent activity?
  • VerrifyError with Guice on Android maven project
  • why , resources in android are converted into HEXA-DECIMAL inside R.java
  • 7 Solutions collect form web for “Intent Filter to Launch My Activity when custom URI is clicked”

    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.

    The Manifest:

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

    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.

    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.

    Have you dried adding a category to your intent-filter:

    <category android:name="android.intent.category.BROWSABLE" />
    

    You could always try sending your emails using HTML and then use an <a> tag around to create the URL. I don’t think there is a way to change the way the Gmail or Mail parse their text, since they probably use the Linkify class.

    Another option would be use use http:// and then just parse for a specific custom subdomain which would provide your users with the option to open in a browser or your application.

    I just ran into this also, but for standard http: scheme urls. Gmail doesn’t appear to add any categories to the Intent. Now I check for BROWSABLE, but I also include a check for !intent.hasCategories() and allow that to go through as well.

    This is solution for me. Thanks @DanO

    <intent-filter>
            <data android:scheme="yourcustomname"/>
            <data android:host="*"/>
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
      </intent-filter>
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.