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.
3 Answers
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).

- 27,623
- 15
- 98
- 151
-
ok when I get a message saying (for instance: myapp://get/256298xxxx) It is supposed to highlight the part myapp://get/256298xxxx on the text. But it doesn't. How should i address this issue? How will the app be launched when the part myapp://get/256298xxxx doesnt even highlight by itself as a link to press on in the text – nishantvodoo Apr 21 '13 at 05:02
-
@nishan_vodoo: That is because _myapp://get/256298xxxx_ is not a valid URL for the SMS app to parse it and show it as a link. At best, it will parse the number sequence as a phone number. You will have to send a valid URL in the SMS. Take a look at a specific example: http://stackoverflow.com/a/3865145/450534. – Siddharth Lele Apr 21 '13 at 05:14
-
Thanks guys for taking time to answer to my question. – nishantvodoo Apr 21 '13 at 05:16
-
@Fred: Yes. This function works regardless of connectivity. However, if the Activity that opens requires Internet, then that is a different matter. – Siddharth Lele Dec 14 '16 at 04:54
-
maybe the correct one is `if (strData.equals` instead of `if (strScreenName.equals` – user2342558 Mar 05 '21 at 10:50
Add an intent-filter to your app that listens for links that follow the format you want your app to be launched on.
However, this will be a global listener, and any link that fits the format even outside the SMS app will trigger your app. So if the user taps a similar link in the web browser, your app will attempt to respond to it.
Additionally, if there is another app besides yours that can handle this link, Android will create a chooser that allows the user to pick whichever app they want to use. There is nothing you can do about this, except suggest that the user make your app the default handler for such links.

- 81,899
- 22
- 187
- 195
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"
<data android:scheme="https" android:host="${hostName}" android:pathPattern="/.*" />
</intent-filter>
Previous answers are OK but don't forget to specify the pattern.
Also define your hostname inside Gradle file like:
android {
defaultConfig {
manifestPlaceholders = [hostName:"subdomain.example.com"]
}
}
More info about manifestPlaceholders
here.

- 1,467
- 14
- 9