0% found this document useful (0 votes)
44 views5 pages

Mad Pract 29

The document outlines the implementation of an Android application that allows users to send SMS messages. It includes the XML layout for the user interface, which consists of two EditText fields for phone number and message input, and a button to send the SMS. The Java code handles SMS sending functionality, permission requests, and user input validation.
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)
44 views5 pages

Mad Pract 29

The document outlines the implementation of an Android application that allows users to send SMS messages. It includes the XML layout for the user interface, which consists of two EditText fields for phone number and message input, and a button to send the SMS. The Java code handles SMS sending functionality, permission requests, and user input validation.
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

Practical No.

29

activity_main29.xml :-

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

<LinearLayout

xmlns:android="[Link]

xmlns:app="[Link]

xmlns:tools="[Link]

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:padding="16dp"

android:gravity="center_horizontal"

tools:context=".MainActivity29">

<EditText

android:id="@+id/et_phone"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Phone Number"

android:padding="12dp"

android:maxLength="10"

android:inputType="phone"

android:background="@color/cardview_shadow_start_color" />

<EditText

android:id="@+id/et_message"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter Message"

android:padding="12dp"

android:minLines="6"
Practical No. 29

android:inputType="textMultiLine"

android:gravity="top"

android:layout_marginTop="8dp"

android:background="@color/cardview_shadow_start_color" />

<Button

android:id="@+id/bt_send"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Send SMS"

android:layout_marginTop="32dp" />

</LinearLayout>

[Link] :-

package [Link].praticle8;

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity29 extends AppCompatActivity {

EditText etPhone, etMessage;

Button btSend;
Practical No. 29

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

etPhone = findViewById([Link].et_phone);

etMessage = findViewById([Link].et_message);

btSend = findViewById([Link].bt_send);

[Link](new [Link]() {

@Override

public void onClick(View view) {

if ([Link]([Link],
[Link].SEND_SMS) ==

PackageManager.PERMISSION_GRANTED) {

sendMessage();

} else {

[Link]([Link], new String[]


{[Link].SEND_SMS},

100);

});

private void sendMessage() {

String sPhone = [Link]().toString().trim();

String sMessage = [Link]().toString().trim();

if (![Link]() && ![Link]()) {

SmsManager smsManager = [Link]();

[Link](sPhone, null, sMessage, null, null);

[Link](getApplicationContext(), "SMS sent successfully!",


Toast.LENGTH_SHORT).show();
Practical No. 29

} else {

[Link](getApplicationContext(), "Enter values first.", Toast.LENGTH_SHORT).show();

@Override

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull


int[]

grantResults) {

[Link](requestCode, permissions, grantResults);

if (requestCode == 100 && [Link] > 0 && grantResults[0] ==

PackageManager.PERMISSION_GRANTED) {

sendMessage();

} else {

[Link](getApplicationContext(), "Permission Denied!",


Toast.LENGTH_SHORT).show();

[Link] :-

[Link]

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

<manifest

xmlns:android="[Link]

package=" [Link].praticle8">

<uses-permission android:name="[Link].SEND_SMS"/>

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"
Practical No. 29

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/Theme.COEXP29">

<activity android:name=".MainActivity29">

<intent-filter>

<action android:name="[Link]" />

<category android:name="[Link]" />

</intent-filter>

</activity>

</application>

</manifest>

******************************OUTPUT****************************

You might also like