Intent Filter to Launch My Activity when custom URI is clicked

43,636

Solution 1

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>

Solution 2

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.

Solution 3

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.

Solution 4

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>
Share:
43,636

Related videos on Youtube

tuxGurl
Author by

tuxGurl

Updated on July 09, 2022

Comments

  • tuxGurl
    tuxGurl almost 2 years

    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>
    
  • tuxGurl
    tuxGurl about 13 years
    I added the BROWSABLE Category and changed data to <data android:scheme="myapp" android:host="myapp.mycompany.com"/> 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
    tuxGurl about 13 years
    Yes, but it doesn't make a difference. :(
  • BigFwoosh
    BigFwoosh about 13 years
    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?
  • tuxGurl
    tuxGurl about 13 years
    In an email the link looks like this: myapp://myapp.mycompany.com. If I try from the browser it redirects to google search.
  • tuxGurl
    tuxGurl about 13 years
    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?
  • DanO
    DanO about 13 years
    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 <a href="myapp://myapp.mycompany.com/index/customerId/12345">La‌​unch My App</a> and that would launch your app.
  • tuxGurl
    tuxGurl about 13 years
    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.
  • DanO
    DanO about 13 years
    Have you tried <data android:scheme="myapp" android:host="*"/> ?
  • Maragues
    Maragues over 12 years
    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.
  • Aiden Fry
    Aiden Fry about 11 years
    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
  • Andrew Arnott
    Andrew Arnott over 10 years
    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.
  • Mark Freeman
    Mark Freeman over 10 years
    We used this same method with a servlet to do the redirect. Worked like a charm.
  • Sazzad Hissain Khan
    Sazzad Hissain Khan almost 5 years
    @tuxGurl how did you fix it?