Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch android app when a link is tapped on SMS

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.

like image 239
nishantvodoo Avatar asked Apr 21 '13 03:04

nishantvodoo


People also ask

How do I insert a hyperlink in a text message android?

To include a link in any text message, just type or paste the full URL into your text. Most messaging platforms will automatically turn the URL into a link that allows contacts to click and access the linked page.


1 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).

like image 150
Siddharth Lele Avatar answered Sep 18 '22 21:09

Siddharth Lele