Launch android app when a link is tapped on SMS

nishantvodoo picture nishantvodoo · Apr 21, 2013 · Viewed 18.3k times · Source

I don't know if many people have tried this but I am trying a build an app that requires user to tap on a link on the sms he/she receives and this will launch the android app. Is it possible to do in android? If yes, how can I do this? I know this can be done in IOS. Any suggestions or help will be appreciated. Thank You.

Answer

Siddharth Lele picture Siddharth Lele · Apr 21, 2013

In you Manifest, under an Activity that you want to handle incoming data from a link clicked in the messaging app, define something like this:

<activity android:name=".SomeActivityName" >

    <intent-filter>
        <category android:name="android.intent.category.DEFAULT" />
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="com.your_package.something" />
    </intent-filter>

</activity>

The android:scheme="" here is what will ensure that the Activity will react to any data with this in it:

<data android:scheme="com.your_package.something" />

In the SomeActivityName (Name used as an illustration. Naturally, you will use your own :-)), you can run a check like this:

Uri data = getIntent().getData();
String strData = data.toString();
if (strScreenName.equals("com.your_package.something://"))  {
    // THIS IS OPTIONAL IN CASE YOU NEED TO VERIFY. THE ACTUAL USAGE IN MY APP IS BELOW THIS BLOCK
}

My app's similar usage:

Uri data = getIntent().getData();
strScreenName = data.toString()
        .replaceAll("com.some_thing.profile://", "")
        .replaceAll("@", "");

I use this to handle clicks on twitter @username links within my app. I need to strip out the com.some_thing.profile:// and the @ to get the username for further processing. The Manifest code, is the exact same (with just the name and scheme changed).