Deep linking in Android with SMS Deep linking in Android with SMS
Deep linking in Android with SMS involves creating a link that, when clicked, opens a specific part of your app.A Deep Link is a URL link that is generated, when anyone clicks on that link our app will be open with a specific activity or a screen. Using this URL we can send a message to our app with parameters. In WhatsApp, we can generate a deep link to send a message to a phone number with some message in it. Here’s a step-by-step guide to help you set it up:

Deep Linking is one of the most important features that is used by various apps to gather data inside their apps in the form of a URL link. So it becomes helpful for the users from other apps to easily share the data with different apps. In this article, we will take a look at the implementation of deep links in our Android App.
1. Handle Deep Linking in Android Manifest
Modify your AndroidManifest.xml
file to handle deep links using an intent filter.
AndroidManifest.xml
<activity android:name=”.Activity”>
<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=”play.google.com”
android:pathPrefix=”/store/apps/details”/>
</intent-filter>
</activity>
2. Handle the Intent in Your Activity
In your Activity.java
, extract the deep link and parse the ID.
Activity.java
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class Activity extends AppCompatActivity {
private static final String TAG = “Activity”;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
TextView textView = findViewById(R.id.taskDetails);
// Get the intent and extract data
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
String taskTrackerId = data.getQueryParameter(“id”); // Extract the ID
textView.setText(“Loading ID: “ + taskTrackerId);
Log.d(TAG, “Received ID: “ + taskTrackerId);
// Fetch data from the database
fetchDataFromDatabase(taskTrackerId);
}
}
private void fetchDataFromDatabase(String taskTrackerId) {
// Simulate database fetching (Replace this with actual DB query)
new Thread(() -> {
try {
Thread.sleep(2000); // Simulate network delay
runOnUiThread(() -> {
// Update UI with fetched data
TextView textView = findViewById(R.id.taskDetails);
textView.setText(“Task Data for ID: “ + Id);
});
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
}
3. Format the SMS Link Correctly
When sending an SMS, make sure the URL is structured properly:
https://play.google.com/store/apps/details?id=com.appname&hl=en-US&id=12345
4. Fetch Data from Database
To fetch the data, use Firebase Firestore, SQLite, or a REST API. Here’s an example using Firebase:
Fetching Task Data from Firebase
private void fetchDataFromDatabase(String taskTrackerId) {
FirebaseFirestore db = FirebaseFirestore.getInstance();
db.collection(“tasks”).document(taskTrackerId)
.get()
.addOnSuccessListener(documentSnapshot -> {
if (documentSnapshot.exists()) {
String taskData = documentSnapshot.getString(“description”);
TextView textView = findViewById(R.id.taskDetails);
textView.setText(“Task Details: “ + taskData);
} else {
Log.d(TAG, “No Task found!”);
}
})
.addOnFailureListener(e -> Log.e(TAG, “Error fetching task”, e));
}
5. Test the Implementation
- Send an SMS with a deep link:
- https://play.google.com/store/apps/details?id=com.packahge name&hl=en-US&id=5678
Click the Link and verify if it:
- Opens the app.
- Extracts the
id
parameter. - Fetches and displays the correct task data.
Conclusion
By following these steps, your app will: ✅ Open when a link from SMS is tapped.
✅ Extract the Id
from the link.
✅ Fetch and display task details from the database.
Let me know if you need further modifications! 🚀