24

I want to open my app from an email URL, basically like the example shown below for Twitter.com.

Email with link:

Email with link

Selection to open app or browser:

Select app or browser

After you click on the app choice, the Twitter app opens:

Open Twitter app

I tried the following code, but it is not working:

<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:host="www.twitter.com" android:scheme="http"></data>
</intent-filter>

If anyone has a proper answer, please write some examples here.

Tot Zam
  • 8,406
  • 10
  • 51
  • 76
Roadies
  • 3,309
  • 2
  • 30
  • 46
  • change android:host value to your url host path and android:scheme to https from http. should work – Vny Kumar Sep 26 '14 at 05:22
  • i want to open my app this is just example.@VnyKumar – Roadies Sep 26 '14 at 05:43
  • @VnyKumar i want to open my app what should i write in manifest file? – Roadies Sep 26 '14 at 05:45
  • Just go through this [Deeplinking](https://developer.android.com/training/app-indexing/deep-linking.html) google document. You will come to know about this deep linking concept. I hope this will help some body. – Aristo Michael Mar 30 '15 at 12:01

3 Answers3

16

The following code worked for me:

<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:host="www.my.app.com"
        android:path="launch"
        android:scheme="http"></data>
</intent-filter>

With the email link set as http://www.my.app.com/launch.

Ref: Launching Android Application from link or email

Community
  • 1
  • 1
hemu
  • 3,199
  • 3
  • 44
  • 66
5

Ex: Your url will be something like https://roadies.com and you have the intent filter in manifest as below

        android:name="com.droid.MainActivity"
        android:label="@string/app_name" >

        <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:host="roadies.com"
            android:scheme="https" />
    </intent-filter>

    </activity>
Vny Kumar
  • 748
  • 7
  • 21
2

For me, none of the answers posted here worked. I tried tens of different syntaxes without any success. I was getting a parsing error while building the app via Cordova.

I finally encountered this answered which led me on the right track.

So I created a hook in the PROJECT_ROOT/hooks/after_prepare/ folder called 010_add_intent_filters.sh. Here is the content of this hook :

!/usr/bin/bash

MANIFEST=./platforms/android/AndroidManifest.xml

grep -q pathPattern $MANIFEST && { print "Manifest already modified. Nothing to do."; exit 0; }

AFTER_LINE='android:name="MainActivity"'
ADDITION='\
  <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="https" android:host="google.com" android:pathPattern=".*"></data>\
  </intent-filter>
';

sed -i -e "/${AFTER_LINE}/a${ADDITION}" $MANIFEST

This finally worked. No modification to config.xml is required if you take the hook path. I hope this helps someone in need.

PS: I am convinced Cordova is a great technology, but I have rarely seen such a badly documented library... How painful it is to work with it is just unbelievable.

Community
  • 1
  • 1
Alexandre Bourlier
  • 3,972
  • 4
  • 44
  • 76