0% found this document useful (0 votes)
9 views2 pages

Exp 29

The document outlines the XML layout and Java code for an Android application that allows users to send SMS messages. It includes user interface components such as TextViews and EditTexts for entering phone numbers and messages, as well as a button to send the SMS. The application requests permission to send SMS and utilizes an Intent to initiate the messaging process.

Uploaded by

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

Exp 29

The document outlines the XML layout and Java code for an Android application that allows users to send SMS messages. It includes user interface components such as TextViews and EditTexts for entering phone numbers and messages, as well as a button to send the SMS. The application requests permission to send SMS and utilizes an Intent to initiate the messaging process.

Uploaded by

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

EXP 29

android:id="@+id/buttonSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send" />

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/
res/android"
android:id="@+id/linearLayout1" package com.example.sms;
android:layout_width="fill_parent"
android:layout_height="fill_parent" import
android:orientation="vertical" > androidx.appcompat.app.AppCompatActivity;

<TextView import android.app.PendingIntent;


android:id="@+id/textViewPhoneNo" import android.content.Intent;
android:layout_width="wrap_content" import android.net.Uri;
android:layout_height="wrap_content" import android.os.Bundle;
android:text="Enter Phone Number : " import android.telephony.SmsManager;
import android.util.Log;
android:textAppearance="?android:attr/textAppea import android.view.Menu;
ranceLarge" /> import android.view.View;
import android.widget.Button;
<EditText import android.widget.EditText;
android:id="@+id/editTextPhoneNo" import android.widget.Toast;
android:layout_width="fill_parent"
android:layout_height="wrap_content" public class MainActivity extends
android:phoneNumber="true" > AppCompatActivity {
</EditText> Button buttonSend;
EditText textPhoneNo;
<TextView EditText textSMS;
android:id="@+id/textViewSMS" @Override
android:layout_width="wrap_content" protected void onCreate(Bundle
android:layout_height="wrap_content" savedInstanceState) {
android:text="Enter SMS Message : " super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
android:textAppearance="?android:attr/textAppea buttonSend = (Button)
ranceLarge" /> findViewById(R.id.buttonSend);
textPhoneNo = (EditText)
<EditText findViewById(R.id.editTextPhoneNo);
android:id="@+id/editTextSMS" textSMS = (EditText)
android:layout_width="fill_parent" findViewById(R.id.editTextSMS);
android:layout_height="wrap_content"
android:inputType="textMultiLine" buttonSend.setOnClickListener(new
android:lines="5" View.OnClickListener() {
android:gravity="top" />
@Override
<Button public void onClick(View v) {
android:supportsRtl="true"
String phoneNo = android:theme="@style/AppTheme">
textPhoneNo.getText().toString(); <activity android:name=".MainActivity">
String sms = textSMS.getText().toString(); <intent-filter>
<action
try{ android:name="android.intent.action.MAIN" />
Intent i = new
Intent(Intent.ACTION_VIEW); <category
i.setData(Uri.parse("smsto:")); android:name="android.intent.category.LAUNCHER
i.setType("vnd.android-dir/mms-sms"); " />
i.putExtra("address", new </intent-filter>
String(textPhoneNo.getText().toString())); </activity>
</application>
i.putExtra("sms_body",textSMS.getText().toString())
; </manifest>
startActivity(Intent.createChooser(i,
"Send sms via:"));
}
catch(Exception e){
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.example.sms">

<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
"

You might also like