Dialer Intent - Android Studio - Kotlin
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 Java
Video
MainActivity.kt
>>Watch For Java
Video
Step 1: Create a new Project or open new 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--> <EditText android: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--> <Button android: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:text="Dial" android:minWidth="120dp" android:textSize="20sp"/> </LinearLayout>
package com.blogspot.atifsoftwares.dialerintent_kotlin import android.content.Intent import android.net.Uri import android.support.v7.app.AppCompatActivity import android.os.Bundle import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { internal var number:String?="" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) //button click handle dialBtn.setOnClickListener { //get input from edit text number = numberEt.text.toString().trim() //Dialer intent val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + Uri.encode(number))) startActivity(intent) } } }
Comments
Post a Comment