24

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>
Community
  • 1
  • 1
tuxGurl
  • 729
  • 1
  • 9
  • 23

7 Answers7

13

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>
Aldan
  • 674
  • 9
  • 23
tuxGurl
  • 729
  • 1
  • 9
  • 23
  • 1
    Hi tuxGurl, but still, this isn't a proper solution as you have to create two links, right? one for iphone and BB and another one for Android. We're experiencing the same problem and after banging our heads against the wall I'm afraid we'll have to send two links in some emails. – Maragues Oct 19 '11 at 13:53
6

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.

BigFwoosh
  • 1,197
  • 10
  • 17
  • I added the `BROWSABLE` Category and changed data to `` but it doesn't help. The email app recognises the `myapp.mycompany.com/index/customerId/12345` as a browser link and doesn't open it in my app. – tuxGurl Apr 08 '11 at 15:28
  • 1
    So the link doesn't contain the `myapp://` part of the URL? Have you tried manually entering a URL in the browser to see if it works? – BigFwoosh Apr 08 '11 at 15:35
  • 10
    In an email the link looks like this: myapp://[myapp.mycompany.com](http://myapp.mycompany.com). If I try from the browser it redirects to google search. – tuxGurl Apr 08 '11 at 17:22
  • @tuxGurl how did you fix it? – Sazzad Hissain Khan Jul 11 '19 at 05:53
4

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.

Michael Nutt
  • 178
  • 1
  • 8
  • 2
    Have you validated this works? 1 - biturl does not accept custom schemas 2 - tinyurl does but its re-direct does not open the app. 3 - if i type in the custom url into the browser bar (chrome) the app does not load as this is not sent as a global intent – Aiden Fry Apr 11 '13 at 13:10
  • I use this approach with success. It solves not only Gmail, but NFC and QR Code transmission of the link so that it's properly interpreted. – Andrew Arnott Dec 29 '13 at 14:13
  • We used this same method with a servlet to do the redirect. Worked like a charm. – Mark Freeman Jan 22 '14 at 19:24
1

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>
emily
  • 11
  • 1
0

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.

dangVarmit
  • 5,641
  • 2
  • 22
  • 24
0

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

<category android:name="android.intent.category.BROWSABLE" />
azharb
  • 979
  • 6
  • 15
0

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.

DanO
  • 10,230
  • 4
  • 41
  • 34
  • I thought the point of using the android:scheme was to allow a URI to be registered to an app like the `PatternRepository` on the Blackberry and the `CFBundleURLName` & `CFBundleURLSchemes` on the iPhone. How do I achieve the same results on the Android? – tuxGurl Apr 08 '11 at 18:11
  • The android:scheme does allow you to launch an application using your custom scheme. But it doesn't automatically parse plain text in other applications. Any time a link is clicked with your custom scheme, your application will launch. So you could send an email with a link Launch My App and that would launch your app. – DanO Apr 11 '11 at 13:41
  • I tried wrapping the link in a href. On the Atrix the link is underlined but tapping it does nothing. On the Galaxy the `myapp.mycompany.com/index/customerId/12345` portion is underlined and opens in a browser. I have updated my manifest in the main post to represent what I am using now. – tuxGurl Apr 11 '11 at 14:42
  • Have you tried `` ? – DanO Apr 11 '11 at 15:18