Latest News

Dialer Intent - Android Studio - Java

This video tutorial will show you how to Input Phone number or *# code and pass it to Dialer Intent using Java language and Android Studio.
>>Watch For Kotlin

Video:

Step 1: Create a new project OR Open your project

Step 2: Code

activity_main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:orientation="vertical"tools:context=".MainActivity"><!--Edit text to input number/code--><EditTextandroid:id="@+id/numberEt"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/bg_edittext"android:hint="Enter Number/Code..."android:inputType="phone"android:minWidth="200dp"android:padding="10dp" /><!--Button to dial number/code--><Buttonandroid:id="@+id/dialBtn"style="@style/Base.Widget.AppCompat.Button.Colored"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:drawableStart="@drawable/ic_call_white"android:drawableLeft="@drawable/ic_call_white"android:drawablePadding="10dp"android:minWidth="120dp"android:text="Dial"android:textSize="20sp" /></LinearLayout>

MainActivity.java

package com.blogspot.atifsoftwares.dialerintent_java;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;public class MainActivity extends AppCompatActivity {//ViewsEditText mNumberEt;Button mDialBtn;//String variable to store text from edit textString number;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//initialize viewsmNumberEt = findViewById(R.id.numberEt);mDialBtn = findViewById(R.id.dialBtn);//button click to dialmDialBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {//get text from edittextnumber = mNumberEt.getText().toString().trim();//Dialer Intent//Uri.encode(string) allows number with * and # symbols to dialIntent intent = new Intent(Intent.ACTION_DIAL , Uri.parse("tel:" + Uri.encode(number)));startActivity(intent);}});}}

Step 3: Run Project

Output
Dialer Intent - Android Studio - Java

0 Response to "Dialer Intent - Android Studio - Java"