Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Deep Linking in Android with Example
Next article icon

Deep Linking in Android with Example

Last Updated : 06 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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. 

What is a Deep Link?

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. Deep links are used to open your app's specific screen with a URL link. 

What are We going to Build in this Article? 

We will be building a simple application in which we will be creating a deep link and on clicking on that link we will be passing our message to our app and displaying that message in a text view. A sample video is given below to get an idea about what we are going to do in this article.

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Project just refer to this article on How to Create New Project in Android Studio. The code can be implemented in both Java and Kotlin Programming Language for Android.

Step 2: Working with activity_main.xml

Navigate to app > res > layout > activity_main.xml and add the below code to it. Comments are added in the code to get to know in detail. 

XML
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"     android:weightSum="5"     tools:context=".MainActivity">     <!-- text view for displaying welcome message -->     <TextView         android:id="@+id/idTVWelcome"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_centerInParent="true"         android:padding="10dp"         android:text="Welcome to "         android:textAlignment="center"         android:textAllCaps="false"         android:textColor="@color/purple_500"         android:textSize="30sp" />     <!-- text view for displaying the organization         name from the link which we have generated -->     <TextView         android:id="@+id/idTVMessage"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@id/idTVWelcome"         android:text="Organization Name"         android:textAlignment="center"         android:textAllCaps="false"         android:textColor="@color/purple_500"         android:textSize="30sp"         android:textStyle="bold" /> </RelativeLayout> 

Step 3: Working with the AndroidManifest.xml file

Navigate to the app > AndroidManifest.xml and add the below code to it. As we are creating a deep link for our MainActivity file so we have to add this code in the MainActivity part. Below is the code which is to be added to the AndroidManifext.xml file. Comments are added in the code to get to know in more detail. 

XML
<!-- as we want to open main activity from our link so we are specifying     only in main activity or we can specify that in different activity as well     on below line we are adding intent filter to our MainActivity -->  <intent-filter>   <!-- below line is to set the action to our intent to view -->   <action android:name="android.intent.action.VIEW" />      <!-- on below line we are adding a default category to our intent -->   <category android:name="android.intent.category.DEFAULT" />      <!-- on below line we are adding a category to make our app browsable -->   <category android:name="android.intent.category.BROWSABLE" />      <!-- on below line we are specifying the host name and       the scheme type from which we will be calling our app -->    <data         android:host="www.chaitanyamunje.com"         android:scheme="https" /> </intent-filter>  <!-- below is the same filter as above just the scheme is changed to http --> <!-- so we can open our app with the url starting with https and http as well --> <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="www.chaitanyamunje.com"     android:scheme="http" /> </intent-filter> 

Below is the complete code for the AndroidManifest.xml file.

XML
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.deeplinks">      <application         android:allowBackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:roundIcon="@mipmap/ic_launcher_round"         android:supportsRtl="true"         android:theme="@style/Theme.DeepLinks">         <activity android:name=".MainActivity">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                  <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>              <!-- as we want to open main activity from our link so we are specifying                 only in main activity or we can specify that in different activity as well -->             <!-- on below line we are adding intent filter to our MainActivity -->             <intent-filter>                 <!-- below line is to set the action to our intent to view -->                 <action android:name="android.intent.action.VIEW" />                                <!-- on below line we are adding a default category to our intent -->                 <category android:name="android.intent.category.DEFAULT" />                                <!-- on below line we are adding a category to make our app browsable -->                 <category android:name="android.intent.category.BROWSABLE" />                                <!-- on below line we are specifying the host name and                     the scheme type from which we will be calling our app -->                 <data                     android:host="www.chaitanyamunje.com"                     android:scheme="https" />             </intent-filter>              <!-- below is the same filter as above just the scheme is changed to http -->             <!-- so we can open our app with the url starting with https and http as well -->             <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="www.chaitanyamunje.com"                     android:scheme="http" />             </intent-filter>         </activity>     </application> </manifest> 

Step 4: Working with MainActivity File

Navigate to app > java > your app's package name > MainActivity File (Java or Kotlin) and add the below code to it. Comments are added in the code to get to know in detail.

Java
import android.net.Uri; import android.os.Bundle; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import java.util.List;  public class MainActivity extends AppCompatActivity {      // creating a variable for our text view     private TextView messageTV;     private Uri uri;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          // initializing our variable         messageTV = findViewById(R.id.idTVMessage);         // getting the data from our intent in our uri.         uri = getIntent().getData();          // checking if the uri is null or not.         if (uri != null) {                        // if the uri is not null then we are getting             // the path segments and storing it in list.             List<String> parameters = uri.getPathSegments();                        // after that we are extracting string              // from that parameters.             String param = parameters.get(parameters.size() - 1);                        // on below line we are setting that string              // to our text view which we got as params.             messageTV.setText(param);         }     } } 
Kotlin
import android.net.Uri import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity  class MainActivity : AppCompatActivity() {      // creating a variable for our text view     private lateinit var messageTV: TextView     private var uri: Uri? = null      override fun onCreate(savedInstanceState: Bundle?) {         super.onCreate(savedInstanceState)         setContentView(R.layout.activity_main)          // initializing our variable         messageTV = findViewById(R.id.idTVMessage)         // getting the data from our intent in our uri.         uri = intent.data          // checking if the uri is null or not.         if (uri != null) {             // if the uri is not null then we are getting             // the path segments and storing it in list.             val parameters = uri!!.pathSegments                        // after that we are extracting string             // from that parameters.             val param = parameters[parameters.size - 1]                        // on below line we are setting that             // string to our text view which             // we got as params.             messageTV.text = param         }     } } 


Now we have added the URL in our AndroidManifest file as https://www.chaitanyamunje.com/hello/GeeksForGeeks. The URL from which we will send messages to our MainActivity File. In the above URL the "https" is our scheme, "www.chaitanyamunje.com" is our hostname and "hello" is our first parameter and "GeeksForGeeks" is a second parameter which we are going to show in our app as an organization name. You can change your parameters according to your requirement. Now run your app and see the output of the app.

Output:

As you have run your app you will get to see the text as the Organization name, now close the application and click on the link which is shown above from the device on which your application is installed. After clicking on that link a pop-up message will be displayed to select the application. Inside that pop-up message select, your application, and your app will be open. We are passing a message as "GeeksForGeeks" which will be displayed in the place of the Organization name.


Next Article
Deep Linking in Android with Example

C

chaitanyamunje
Improve
Article Tags :
  • Java
  • Technical Scripter
  • Kotlin
  • Android
  • Technical Scripter 2020
Practice Tags :
  • Java

Similar Reads

    Android - Deep Linking with Kotlin
    Deep Links are seen in most applications where users can use these links to redirect to any specific screen or activity within the application. We can also pass data using these links within our application. In this article, we will take a look at Implementing Deep Links in Android applications usin
    5 min read
    OpenIntents in Android with Example
    OI refers to the "OpenIntents" project in Android are a way for one app to request an action from another app. This can be done using either explicit or implicit intents, allowing them to share functionality. The OpenIntents project provides a set of commonly-used intents that can be used by develop
    4 min read
    Line Graph View in Android with Example
    If you are looking for a view to represent some statistical data or looking for a UI for displaying a graph in your app then in this article we will take a look on creating a line graph view in our Android App using the GraphView library. What we are going to build in this article? We will be buildi
    3 min read
    Context Menu in Android with Example
    In Android, there are three types of menus available to define a set of options and actions in the Android apps. Here in this article let's discuss the detail of the Context Menu. In Android, the context menu is like a floating menu and arises when the user has long-pressed or clicked on an item and
    4 min read
    Android ListView in Java with Example
    A ListView in Android is a type of AdapterView that displays a vertically scrollable list of items, with each item positioned one below the other. Using an adapter, items are inserted into the list from an array or database efficiently. For displaying the items in the list method setAdaptor() is use
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences