SlideShare a Scribd company logo
7
Most read
9
Most read
10
Most read
Presented by :
Rushika Shah
Chandni Chauhan
1.Create
New
Application
2.Add
Permission
4.Moidify
activity_main
.xml
3.Modify
MainActivity.kt 5.Run the
App
2. Give App Permission To Use SEND SMS in
app -> manifests-> Android Manifest.xml
File New Project
Empty
Activity
Project
Configuration
Finish
1. Create new Kotlin Application in Android Studio
<uses-permission android:name="android.permission.SEND_SMS“ />
3. Modify MainActivity.kt file
app -> java ->com.example.{project_name} ->MainActivity.kt
import android.Manifest
import android.content.pm.PackageManager
import android.os.Bundle
import android.telephony.SmsManager
import android.text.TextUtils
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
Import all
classes
class MainActivity : AppCompatActivity() {
lateinit var editTextNumber : EditText
lateinit var editTextMessage : EditText
lateinit var button :Button
private val permissionRequest = 101
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
editTextNumber = findViewById(R.id.editTextNum)
editTextMessage = findViewById(R.id.editTextMsg)
button = findViewById(R.id.btnSendMsg)
title = "Send SMS"
}
Access widgets for
perform Task
• Check whether permission is already granted or not. If permission isn’t
already granted, request user for the permission.
ContextCompat.checkSelfPermission(thisActivity,Manifest.permission.
Permission_Name)
• When PERMISSION_DENIED is returned from the checkSelfPermission()
method in the above syntax, we need to prompt the user for that
permission. Android provides several methods that can be used to
request permission, such as requestPermissions().
ActivityCompat.requestPermissions(this,arrayOf(Manifest.permission.Perm
ission_Name), permissionRequest)
fun sendMessage(view: View) {
val permissionCheck = ContextCompat.checkSelfPermission(this,
Manifest.permission.SEND_SMS)
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
myMessage()
}
else {
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.SEND_SMS), permissionRequest)
}
}
Check User
Permission
• SMSManager class manages operations like sending a text message,
data message, and multimedia messages (MMS). For sending a text
message method sendTextMessage() is used likewise for multimedia
message sendMultimediaMessage() and for data
message sendDataMessage() method is used.
• we want to send Text message so we will use sendTextMessage() here.
SmsManager.sendTextMessage(String destinationAddress, String scAddress,
String text, PendingIntent sentIntent,PendingIntent deliveryIntent)
private fun myMessage() {
val myNumber: String = editTextNumber.text.toString().trim()
val myMsg: String = editTextMessage.text.toString().trim()
if (myNumber == "" || myMsg == "") {
Toast.makeText(this, "Field cannot be empty",
Toast.LENGTH_SHORT).show()
}
else {
if (TextUtils.isDigitsOnly(myNumber)) {
val smsManager: SmsManager = SmsManager.getDefault()
smsManager.sendTextMessage(myNumber, null, myMsg, null, null)
Toast.makeText(this, "Message Sent", Toast.LENGTH_SHORT).show()
}
else {
Toast.makeText(this, "Please enter the correct number",
Toast.LENGTH_SHORT).show()
}
}
}
}
SmsManager.sendText
Message() for sending
Message
4. Modify activity_main.xml file
app -> res -> layout -> activity_main.xml
<EditText
android:id="@+id/editTextNum"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter mobile number"
android:textColor="@android:color/black" />
<EditText
android:id="@+id/editTextMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your message"
android:textColor="@android:color/black" />
Add EdiText For
Mobile Number
Add EdiText For
Text Message
<Button
android:id="@+id/btnSendMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:onClick="sendMessage"
android:text="Send Message" />
Add Button For
Send SMS
5. Run the Application
Click on Run Application or Press Alt+Shift+F10
Here we are running Application on the android Device, so we will
find the Application with Android icon on your Device as shown
below.
Send Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with Kotlin

More Related Content

PDF
Android notification
PPTX
JAVA AWT
PPTX
Android Layout.pptx
PPTX
Event handling
PPT
Asp.net server controls
PPT
Java Networking
PPT
Developing an ASP.NET Web Application
PPS
Java Exception handling
Android notification
JAVA AWT
Android Layout.pptx
Event handling
Asp.net server controls
Java Networking
Developing an ASP.NET Web Application
Java Exception handling

What's hot (20)

PPTX
Introduction to php
PDF
JavaScript - Chapter 11 - Events
PPTX
Client side scripting using Javascript
PPS
Wrapper class
PPTX
PPT
SQLITE Android
PPT
VB.net
PPSX
JDBC: java DataBase connectivity
PPTX
Content provider in_android
PPTX
Windows form application - C# Training
PPT
android activity
PPS
Jdbc architecture and driver types ppt
PPT
Javascript
PPT
Data structures using c
PPTX
Broadcast Receiver
PPT
Data Storage In Android
PDF
Lecture 2 role of algorithms in computing
PDF
Introduction to fragments in android
PPTX
Introduction to ASP.NET
Introduction to php
JavaScript - Chapter 11 - Events
Client side scripting using Javascript
Wrapper class
SQLITE Android
VB.net
JDBC: java DataBase connectivity
Content provider in_android
Windows form application - C# Training
android activity
Jdbc architecture and driver types ppt
Javascript
Data structures using c
Broadcast Receiver
Data Storage In Android
Lecture 2 role of algorithms in computing
Introduction to fragments in android
Introduction to ASP.NET
Ad

Similar to Send Sms with SmsManager Api In Android with Kotlin (8)

PPTX
Msbte__________________CHPter_6_MAD.pptx
PPTX
Android
PPT
Android introduction by vidya topa
PDF
android level 3
PPTX
Telephony API
ODP
PDF
Android Telephony Manager and SMS
PPTX
Create an other activity lesson 3
Msbte__________________CHPter_6_MAD.pptx
Android
Android introduction by vidya topa
android level 3
Telephony API
Android Telephony Manager and SMS
Create an other activity lesson 3
Ad

Recently uploaded (20)

PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
System and Network Administraation Chapter 3
PDF
Nekopoi APK 2025 free lastest update
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
System and Network Administration Chapter 2
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
history of c programming in notes for students .pptx
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
System and Network Administraation Chapter 3
Nekopoi APK 2025 free lastest update
Computer Software and OS of computer science of grade 11.pptx
System and Network Administration Chapter 2
PTS Company Brochure 2025 (1).pdf.......
How to Choose the Right IT Partner for Your Business in Malaysia
Odoo Companies in India – Driving Business Transformation.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Reimagine Home Health with the Power of Agentic AI​
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
history of c programming in notes for students .pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Designing Intelligence for the Shop Floor.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
2025 Textile ERP Trends: SAP, Odoo & Oracle
wealthsignaloriginal-com-DS-text-... (1).pdf

Send Sms with SmsManager Api In Android with Kotlin

  • 1. Presented by : Rushika Shah Chandni Chauhan
  • 3. 2. Give App Permission To Use SEND SMS in app -> manifests-> Android Manifest.xml File New Project Empty Activity Project Configuration Finish 1. Create new Kotlin Application in Android Studio <uses-permission android:name="android.permission.SEND_SMS“ />
  • 4. 3. Modify MainActivity.kt file app -> java ->com.example.{project_name} ->MainActivity.kt import android.Manifest import android.content.pm.PackageManager import android.os.Bundle import android.telephony.SmsManager import android.text.TextUtils import android.view.View import android.widget.Button import android.widget.EditText import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat Import all classes
  • 5. class MainActivity : AppCompatActivity() { lateinit var editTextNumber : EditText lateinit var editTextMessage : EditText lateinit var button :Button private val permissionRequest = 101 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) editTextNumber = findViewById(R.id.editTextNum) editTextMessage = findViewById(R.id.editTextMsg) button = findViewById(R.id.btnSendMsg) title = "Send SMS" } Access widgets for perform Task
  • 6. • Check whether permission is already granted or not. If permission isn’t already granted, request user for the permission. ContextCompat.checkSelfPermission(thisActivity,Manifest.permission. Permission_Name)
  • 7. • When PERMISSION_DENIED is returned from the checkSelfPermission() method in the above syntax, we need to prompt the user for that permission. Android provides several methods that can be used to request permission, such as requestPermissions(). ActivityCompat.requestPermissions(this,arrayOf(Manifest.permission.Perm ission_Name), permissionRequest)
  • 8. fun sendMessage(view: View) { val permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS) if (permissionCheck == PackageManager.PERMISSION_GRANTED) { myMessage() } else { ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.SEND_SMS), permissionRequest) } } Check User Permission
  • 9. • SMSManager class manages operations like sending a text message, data message, and multimedia messages (MMS). For sending a text message method sendTextMessage() is used likewise for multimedia message sendMultimediaMessage() and for data message sendDataMessage() method is used. • we want to send Text message so we will use sendTextMessage() here. SmsManager.sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent,PendingIntent deliveryIntent)
  • 10. private fun myMessage() { val myNumber: String = editTextNumber.text.toString().trim() val myMsg: String = editTextMessage.text.toString().trim() if (myNumber == "" || myMsg == "") { Toast.makeText(this, "Field cannot be empty", Toast.LENGTH_SHORT).show() } else { if (TextUtils.isDigitsOnly(myNumber)) { val smsManager: SmsManager = SmsManager.getDefault() smsManager.sendTextMessage(myNumber, null, myMsg, null, null) Toast.makeText(this, "Message Sent", Toast.LENGTH_SHORT).show() } else { Toast.makeText(this, "Please enter the correct number", Toast.LENGTH_SHORT).show() } } } } SmsManager.sendText Message() for sending Message
  • 11. 4. Modify activity_main.xml file app -> res -> layout -> activity_main.xml <EditText android:id="@+id/editTextNum" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter mobile number" android:textColor="@android:color/black" /> <EditText android:id="@+id/editTextMsg" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Enter your message" android:textColor="@android:color/black" /> Add EdiText For Mobile Number Add EdiText For Text Message
  • 13. 5. Run the Application Click on Run Application or Press Alt+Shift+F10 Here we are running Application on the android Device, so we will find the Application with Android icon on your Device as shown below.