The Wayback Machine - https://web.archive.org/web/20240907184707/https://www.geeksforgeeks.org/how-to-open-dialer-in-android-through-intent/
Open In App

How to open dialer in Android through Intent?

Last Updated : 03 Nov, 2020
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The phone dialer is an activity available with the Android operating system to call a number. Usually, such activity may or may not have an EditText, for taking the number as input, and a Call button. When the user presses the Call button, it invokes the dialer app activity. Use of ‘tel:’ prefix is recommended, else java.lang.IllegalStateException will be thrown. Action_Dial doesn’t require any permission. Below is the code for MainActivity file in both Java and Kotlin.

Java




package com.geeksforgeeks.gfg.dial;
  
// importing packages
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
  
public class MainActivity extends AppCompatActivity {
  
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
  
        // Binding MainActivity.java with 
        // activity_main.xml file
        setContentView(R.layout.activity_main);
      
    }
  
    // This function is called when button is clicked.
    public  void Call(View v)
    {
        // Find the EditText by its unique ID
        EditText e = (EditText)findViewById(R.id.editText);
  
        // show() method display the toast with message 
        // "clicked"
        Toast.makeText(this, "clicked", Toast.LENGTH_LONG)
             .show();
  
        // Use format with "tel:" and phoneNumber created is 
        // stored in u.
        Uri u = Uri.parse("tel:" + e.getText().toString());
  
        // Create the intent and set the data for the 
        // intent as the phone number.
        Intent i = new Intent(Intent.ACTION_DIAL, u);
  
        try
        {
            // Launch the Phone app's dialer with a phone 
            // number to dial a call.
            startActivity(i); 
        }
        catch (SecurityException s)
        {
            // show() method display the toast with 
            // exception message.
            Toast.makeText(this, "An error occurred", Toast.LENGTH_LONG)
                 .show();
        }
    }
}


Kotlin




package com.geeksforgeeks.gfg.dial
  
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.gfgreviewinjava.R
  
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
  
        // Binding MainActivity.java with
        // activity_main.xml file
        setContentView(R.layout.activity_main)
    }
  
    // This function is called when button is clicked.
    fun Call(v: View?) {
        // Find the EditText by its unique ID
        val e = findViewById<View>(R.id.editText) as EditText
  
        // show() method display the toast with message
        // "clicked"
        Toast.makeText(this, "clicked", Toast.LENGTH_LONG)
                .show()
  
        // Use format with "tel:" and phoneNumber created is
        // stored in u.
        val u = Uri.parse("tel:" + e.text.toString())
  
        // Create the intent and set the data for the
        // intent as the phone number.
        val i = Intent(Intent.ACTION_DIAL, u)
        try {
            // Launch the Phone app's dialer with a phone
            // number to dial a call.
            startActivity(i)
        } catch (s: SecurityException) {
            // show() method display the toast with
            // exception message.
            Toast.makeText(this, "An error occurred", Toast.LENGTH_LONG)
                    .show()
        }
    }
}


In order to make a direct call without switching into dialer activity, you need to add Intent.ACTION_CALL in place of Intent.ACTION_DIAL.
activity_main.xml
 

XML




<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:tools="http://schemas.android.com/tools"
  
    <!-- covers entire width of the screen -->
    android:layout_width="match_parent"
  
    <!-- covers entire height of the screen -->
    android:layout_height="match_parent"
  
    tools:context="com.example.hp.dial.MainActivity">
  
    <EditText
        android:id="@+id/editText"
        <!-- covers as much width as required. -->
        android:layout_width="wrap_content"
  
        <!-- covers as much height as required. -->
        android:layout_height="wrap_content"
  
        <!-- left spacing from the parent layout-->
        android:layout_marginLeft="8dp"
  
        <!-- right spacing from the parent layout-->
        android:layout_marginRight="8dp"
  
        <!-- top spacing from the parent layout-->
        android:layout_marginTop="65dp"
  
        <!-- hint works as a place holder -->
        android:hint="Phone No."
  
        <!-- Expressing the given input should be phone no -->
        android:inputType="phone"
  
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
  
    <Button
        android:id="@+id/button"
  
        <!-- covers as much width as required. -->
        android:layout_width="wrap_content"
  
        <!-- covers as much height as required. -->
        android:layout_height="wrap_content"
  
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="67dp"
  
        <!-- name of function is Call, and it is -->
        <!-- invoked when the button is clicked.-->
        android:onClick="Call"
  
        android:text="DIAL"
  
        <!-- below are the positions of the button -->
        <!-- with respect to editText and parent layout. -->
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/editText"
    />
</android.support.constraint.ConstraintLayout>


In AndroidManifest.xml, include the below permission to directly call without opening in a dialer. To make a call through open in a dialer, below permission is not needed. 
 

uses-permission android:name="android.permission.CALL_PHONE"

 

Figure 1. Enter Phone no.

 

Figure 2. Open the dialer activity.

 



Previous Article
Next Article

Similar Reads

Android - Open Dialer Through Intent using Jetpack Compose
The phone dialer is an activity in the android application that is used to make a phone call within the android device. The dialer activity is used to dial a phone number and make a call. In this article, we will take a look at How to open a dialer in the android application through Intent in our android application using Jetpack Compose. A sample
5 min read
Difference Between Implicit Intent and Explicit Intent in Android
The intent is a messaging object which tells what kind of action to be performed. The intent’s most significant use is the launching of the activity. The intent is a passive data structure holding an abstract description of an action to be performed. Body of Intent: There are two important things in intent action: The general action to be performed
4 min read
How to Open Camera Through Intent and Display Captured Image in Android?
Pre-requisites: Android App Development Fundamentals for Beginners Guide to Install and Set up Android Studio Android | Starting with first app/android project Android | Running your first Android app The purpose of this article is to show how to open a Camera from inside an App and click the image and then display this image inside the same app. A
5 min read
How to Open a Specific Folder Via Intent in Android?
In this article, we are going to open a specific folder from our App. This feature is useful in many cases. Most of the time when we want to upload any file then the app simply opens the file manager. But we can implement this feature for effective use like whenever any user wants to upload any file then the user will simply choose the folder name
3 min read
Intent Redirection and App Security in Android 13
There have been a lot of security concerns over time over various Android resources, and as we continue moving towards the digital age, they will continue to keep arising. Android 13 comes in command by bringing certain checks into places that help to sustain and improve the overall security of the Android system, many changes introduced are by eit
4 min read
Intent Filter in Android with Demo App
The intent is a messaging object which tells what kind of action to be performed. The intent’s most significant use is the launching of the activity. Intent facilitates the communication between the components. Note: App components are the basic building blocks of App. Fundamental use case of Intents Starting Activity An activity represents the sin
5 min read
How to Pass Video Using Intent Between Activities in Android?
In android, An Intent provides a facility for performing late runtime binding between the code in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed. What w
4 min read
Show PDF Using Intent in Android
Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Further, it was developed for smartwatches and Android TV. Each of them has a specialized interface. Android has been one of the best-selling OS for smartphones. Android OS was developed by Android Inc. which Google bough
3 min read
Start a New Activity using Intent in Android using Jetpack Compose
In Android OS, an Intent is a mechanism used to navigate a user to another activity or application to achieve a specific task. In general, Intents are used to progress to the next activity or come back to the previous activity. In this article, we will show you how you could start a New Activity using Intent in Android using Jetpack Compose. Follow
4 min read
How to Get Extra Data From Intent in Android?
There are many parts in android applications where we have to pass data from one activity to another activity for performing some data-related operations on it. For passing and retrieving the data there are several different methods such as passing data through bundles and others. In this article, we will take a look at How to get extra data to sen
5 min read
How to Share Image From URL with Intent in Android?
In this article, we will see how can we share images and text with Android Intent. In this activity URL of an image to be shared will be given with extra text and we will open the Dialog where the user chooses using which he wants to share this image as shown on the screen. A sample video is given below to get an idea about what we are going to do
5 min read
Intent Service in Android with Example
An IntentService is a subclass of Service in Android that is used to handle asynchronous requests (expressed as "Intents") on demand. It runs in the background and stops itself once it has processed all the intents that were sent to it. An IntentService in Java and Kotlin: C/C++ Code class MyIntentService : IntentService(&quot;MyIntentService&quot;
5 min read
How to Send Email in Android App Without Using Intent?
It is crucial to establish an email connection in the Android application. This enables us to send important messages to users. For example, when the user joins the app first time sending a welcome email is a common practice. Additionally in some applications if a user signs in from a new location a notification is sent to inform them of this activ
5 min read
What is Intent in Android?
In Android, it is quite usual for users to witness a jump from one application to another as a part of the whole process, for example, searching for a location on the browser and witnessing a direct jump into Google Maps or receiving payment links in Messages Application (SMS) and on clicking jumping to PayPal or GPay (Google Pay). This process of
4 min read
How to Open a URL in Android's Web Browser in an Android Application?
It might be essential to launch a browser separately while using an Android application to access a URL. Any action made on Views using Action Listeners has the potential to initiate the task of accessing a URL. In this article, we will learn about How we can Open a URL in Android's Web Browser from an Android Application. For this article, we will
2 min read
How to Update User's Profile After Signing Through GitHub using Firebase in Android?
In this article, we will learn to update user's profiles who signed in to the app through GitHub. The profile will be updated through the user's GitHub information like GitHub Id, name, followers, following, etc. Let's start! Step 1: First set up your app so that users can be signed in through GitHub. So you need to authenticate the user using GitH
7 min read
How to Improve Your Android Coding Through Annotation?
Annotations are a type of metadata. Metadata, on the other hand, is a collection of data that provides information about other data. There are numerous ways to use annotations in Android. However, in this section, we will discuss how annotations may be utilized to better our Android coding. Officially, Android already has support annotations, which
3 min read
How to Change Android TextView Remotely Through Firebase?
First Of all, let's understand how we are going to do this first we will be using one feature of Firebase which is RemoteConfig, and with the help of that we are going to change the TextView. The basic principle of that you can change the text view of the app without pushing any update which is one of the main advantages of the Remote Config. To le
6 min read
Open Specific Settings Using Android Application
In android development, the phase comes where the app needs specific settings to be modified manually by the user. So at that time developer directs the user to open specific settings and modify them. So in this article, it has been discussed how to open specific settings and make the user change them easily. Step 1: Create a new Empty Activity and
3 min read
Best Open Source Android Libraries
Libraries are the most useful and convenient tool for android app development. A developer can save time, skip writing the pseudo-code every time, improve the code's readability, and even perform complex tasks in easy ways and with fewer lines of the code. Also, most of you will be familiar with open-source environments. You would also know how ope
7 min read
How to Check if Application is Installed in Your Android Phone and Open the App?
In this article, we are going to check if a particular app is installed on our phones or not. If yes then we will be having an option to open the app. Else it will show a toast message saying Not available. So here we are going to learn how to implement that feature. Note that we are going to implement this project using the Java language. Step by
3 min read
How to Open an External URL on Button Click in Android using Jetpack compose?
Many times in android applications we have to open a web page from an URL inside the default browser of the user's device. In that case, we have to simply pass that URL to the web browser to load that page. In this article, we will take a look at How to open a URL in an android web browser from our android application using Jetpack Compose. A sampl
5 min read
Android Jetpack Compose - Open Specific Settings Screen
Many times while the user is using an android application he has to edit a few settings in the device to use the applications such as providing any permissions from the settings application to use that specific feature within the application. For changing these settings we have to open a specific setting screen from our android application to modif
6 min read
How to Open PDF From URL in Android Without Any Third Party Libraries?
There are lots of libraries that are available online but it takes lots of space and time to render you can see these articles if you want to load pdf using third-party libraries Load PDF from URL in Android. But today we are going to load PDFs without using any third-party libraries the main purpose of that is it reduce the APK size and it is so e
4 min read
Android - Detect Open or Closed Eyes Using ML Kit and CameraX
Google's ML kit is one of the best-trained models for face detection and its characteristics. Integrating with your own CameraX library can be quite a challenging task. so we are going to build an Android app that will detect whether a person's eyes are open or closed in real time. This process going to be long so without delay let's deep dive into
10 min read
How to Contribute to Open Source Android Projects on GitHub?
Contributing to open-source projects is an excellent way for developers to improve their skills, gain experience, and give back to the community. Android projects on GitHub offer a rich ecosystem where you can collaborate, learn, and make a tangible impact. This guide will walk you through the steps to contribute to open-source Android projects on
3 min read
Android Manifest File in Android
Every project in Android includes a Manifest XML file, which is AndroidManifest.xml, located in the root directory of its project hierarchy. The manifest file is an important part of our app because it defines the structure and metadata of our application, its components, and its requirements. This file includes nodes for each of the Activities, Se
5 min read
Android | Android Application File Structure
It is very important to know about the basics of Android Studio's file structure. In this article, some important files/folders, and their significance is explained for the easy understanding of the Android studio work environment. In the below image, several important files are marked: All of the files marked in the above image are explained below
3 min read
What's Android Interface Definition Language (AIDL) in Android?
The Android Interface Definition Language (AIDL) is analogous to other IDLs you would possibly have worked with. It allows you to define the programming interface that both the client and repair agree upon so as to speak with one another using interprocess communication (IPC). Traditionally the Android way a process cannot access the memory of some
7 min read
Android | Running your first Android app
After successfully Setting up an Android project, all of the default files are created with default code in them. Let us look at this default code and files and try to run the default app created. The panel on the left side of the android studio window has all the files that the app includes. Under the java folder, observe the first folder containi
3 min read
Article Tags :
Practice Tags :