Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
6 views4 pages

Android SMS Code

The document contains the code for an Android application that allows users to send SMS messages. It includes the layout file 'activity_main.xml' for the user interface, 'MainActivity.java' for the functionality to send SMS, and 'AndroidManifest.xml' for permissions and application configuration. The app features input fields for mobile number and message, and a button to send the SMS using the SmsManager class.

Uploaded by

abcyadav3732
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Android SMS Code

The document contains the code for an Android application that allows users to send SMS messages. It includes the layout file 'activity_main.xml' for the user interface, 'MainActivity.java' for the functionality to send SMS, and 'AndroidManifest.xml' for permissions and application configuration. The app features input fields for mobile number and message, and a button to send the SMS using the SmsManager class.

Uploaded by

abcyadav3732
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

activity_main.

xml
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:id="@+id/fstTxt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="100dp"

android:layout_marginTop="150dp"

android:text="Mobile No" />

<EditText

android:id="@+id/mblTxt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="100dp"

android:ems="10"/>

<TextView

android:id="@+id/secTxt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Message"

android:layout_marginLeft="100dp" />

<EditText

android:id="@+id/msgTxt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="100dp"

android:ems="10" />

<Button
android:id="@+id/btnSend"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginLeft="100dp"

android:text="Send SMS" />

</LinearLayout>

MainActivity.java
package com.tutlane.sendsmsexample;

import android.content.Intent;

import android.net.Uri;

import android.provider.Telephony;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.telephony.SmsManager;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity

private EditText txtMobile;

private EditText txtMessage;

private Button btnSms;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
txtMobile = (EditText)findViewById(R.id.mblTxt);

txtMessage = (EditText)findViewById(R.id.msgTxt);

btnSms = (Button)findViewById(R.id.btnSend);

btnSms.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

try{

SmsManager smgr = SmsManager.getDefault();

smgr.sendTextMessage(txtMobile.getText().toString(),null,txtMessage.getText().toString(

),null,null);

Toast.makeText(MainActivity.this,

Toast.LENGTH_SHORT).show();

catch (Exception e){

"SMS

Sent

Successfully",

Toast.makeText(MainActivity.this, "SMS Failed to Send, Please try again",

Toast.LENGTH_SHORT).show();

});

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.tutlane.sendsmsexample">

<uses-permission android:name="android.permission.SEND_SMS"/>
<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/AppTheme">

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

You might also like