0% found this document useful (0 votes)
83 views40 pages

Mad Exp1

MAD Lab Manual
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)
83 views40 pages

Mad Exp1

MAD Lab Manual
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

Name: Chaitra.

M
Reg No: 9824037018

Ex. No.1 Develop An Android Application To Create Login Page

Date:

Aim:

To Develop an android application To Create Login Page

Procedure

Step 1: Form design

1. Create new project.

2. Click res directory -> layout -> activity_main.xml -> Design

3. Insert three TextView control. Give the id property as “textViewLogin”,


“textViewName” and “textViewPassword” and give text property as “Login”,
“Username” and ”Password” respectively.

4. Insert two EditText control. Give the id as “editTextName” and “editTextPassword”


respectively.

5. Insert two Button control. Give the id as “buttonOk” and “buttonReset” and give text
property as “OK” and “Reset” respectively.

Step 2: Open java -> MainActivity.java and write the code needed for button “OK” and
“Reset” event triggering (refer program).

Step 3: Run the program using following steps in Android Emulator.


Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.
Name: Chaitra.M
Reg No: 9824037018

Program:

Design view code file name: 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/loginText"
android:textSize="36dp"
android:textAlignment="center"
android:textStyle="bold" />

<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/Username"
android:drawablePadding="8dp"
android:hint="Username"
android:padding="8dp"
android:textColor="@color/black"
android:layout_marginTop="40dp" />

<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/Password1"
android:drawablePadding="8dp"
android:hint="Password"
android:padding="8dp"
android:textColor="@color/black"
android:layout_marginTop="40dp"
android:inputType="textPassword" /> <Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
Name: Chaitra.M
Reg No: 9824037018
android:layout_height="50dp"
android:text="Login" android:textSize="18sp"
android:layout_marginTop="30dp" />

</LinearLayout>

Login page activity code: MainActivity.java package

com.example.login;

import android.os.Bundle; import


android.view.View; import
android.widget.Button; import
android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge; import


androidx.appcompat.app.AppCompatActivity; import
androidx.core.graphics.Insets; import
androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

EditText username;
EditText password;
Button loginButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main); username
= findViewById(R.id.Username); password =
findViewById(R.id.Password1);
loginButton = findViewById(R.id.loginButton);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(username.getText().toString().equals("user")&&
password.getText().toString().equals("1234")){
Toast.makeText(MainActivity.this, "Login Successful",
Toast.LENGTH_SHORT).show();
Name: Chaitra.M
Reg No: 9824037018
}else{
Toast.makeText(MainActivity.this,"Login
Failed",Toast.LENGTH_SHORT).show();
}
}

});
}}

Output

Result:

Thus to create login page was developed using Android Studio and the output was verified.
Name: Chaitra.M
Reg No: 9824037018

Ex.No.2 Develop An Android Application To Working With Colours And Images

Date:

Aim:

To Develop an android application To Working with Colours and Images

Procedure

Step 1: Form design

1. Create new project.

2. Click res directory -> layout -> activity_main.xml -> Design

3. Insert three TextView control. Give the id property as “textViewLogin”,


“textViewName” and “textViewPassword” and give text property as “Login”,
“Username” and ”Password” respectively.

4. Insert two EditText control. Give the id as “editTextName” and “editTextPassword”


respectively.

5. Insert two Button control. Give the id as “buttonOk” and “buttonReset” and give text
property as “OK” and “Reset” respectively.

Step 2: Open java -> MainActivity.java and write the code needed for button “OK” and
“Reset” event triggering (refer program).

Step 3: Run the program using following steps in Android Emulator.


Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.
Name: Chaitra.M
Reg No: 9824037018

Program:

Design view code file name: 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity"
android:orientation="vertical" android:layout_gravity="center"
android:background="@drawable/picker1">

<ImageView
android:id="@+id/ImageView"
android:layout_width="350dp"
android:layout_height="350dp"
android:src="@drawable/color3"
/>

<View
android:id="@+id/colorView"
android:layout_width="wrap_content"
android:layout_height="120dp"
/>

<TextView
android:id="@+id/resultTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HEX: \nRGB"
android:textSize="18sp"
android:textColor="#000"
/>

</LinearLayout>
Name: Chaitra.M
Reg No: 9824037018
Colours page activity code: MainActivity.java package

com.example.colors;

import android.graphics.Bitmap;
import android.os.Bundle; import
android.view.MotionEvent; import
android.view.View; import
android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

ImageView mImageView;
TextView mResultTv;
View mColorView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

mImageView = findViewById(R.id.ImageView); mResultTv


= findViewById(R.id.resultTV);
mColorView = findViewById(R.id.colorView);

mImageView.setDrawingCacheEnabled(true);
mImageView.buildDrawingCache(true); mImageView.setOnTouchListener(new
View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() ==
MotionEvent.ACTION_MOVE) {
Bitmap bitmap = mImageView.getDrawingCache();

if (bitmap != null) { int x


= (int) event.getX(); int y
= (int) event.getY();
if (x >= 0 && y >= 0 && x < bitmap.getWidth() && y < bitmap.getHeight()) {
int pixelColor = bitmap.getPixel(x, y);
mResultTv.setText("RGB: " + android.graphics.Color.red(pixelColor) + ", " +
android.graphics.Color.green(pixelColor) + ", " +
Name: Chaitra.M
Reg No: 9824037018
android.graphics.Color.blue(pixelColor));
mColorView.setBackgroundColor(pixelColor);
}
}
return true;
}
return false;

Output:

Result:

Thus to working with colours and Images was developed using Android Studio and the
output was verified.
Name: Chaitra.M
Reg No: 9824037018

Ex. No.3 Develop An Android Application To Create A Native Calculator App

Date:

Aim:

To Develop an android application to create a native calculator app

Procedure

Step 1: Form design

1. Create new project.

2. Click res directory -> layout -> activity_main.xml -> Design

3. Insert three TextView control. Give the id property as “textViewLogin”,


“textViewName” and “textViewPassword” and give text property as “Login”,
“Username” and ”Password” respectively.

4. Insert two EditText control. Give the id as “editTextName” and “editTextPassword”


respectively.

5. Insert two Button control. Give the id as “buttonOk” and “buttonReset” and give text
property as “OK” and “Reset” respectively.

Step 2: Open java -> MainActivity.java and write the code needed for button “OK” and
“Reset” event triggering (refer program).

Step 3: Run the program using following steps in Android Emulator.


Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.
Name: Chaitra.M
Reg No: 9824037018
Program:

Design view code file name: activity main.xml

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


<RelativeLayout 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" tools:context=".MainActivity"
android:background="@drawable/Leo" android:padding="20dp"
>

<TextView
android:id="@+id/screen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textStyle="bold"
android:textSize="60dp"
android:textColor="#FFFFFF"
android:paddingHorizontal="15dp"
android:paddingVertical="35dp"
android:layout_above="@id/nums"/>

<LinearLayout
android:id="@+id/nums"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:paddingTop="20dp">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<Button
android:id="@+id/on"
android:text="ON"
style="@style/Button1"/>
<Button
android:id="@+id/num7"
Name: Chaitra.M
Reg No: 9824037018
android:text="7"
style="@style/Button2"/>
<Button
android:id="@+id/num4"
android:text="4"
style="@style/Button2"/>
<Button
android:id="@+id/num1"
android:text="1"
style="@style/Button2"/>
<Button
android:id="@+id/del"
android:text="DEL"
style="@style/Button1"/>
>
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<Button
android:id="@+id/off"
android:text="off"
style="@style/Button1"/>
<Button
android:id="@+id/num8"
android:text="8"
style="@style/Button2"/>
<Button
android:id="@+id/num5"
android:text="5"
style="@style/Button2"/>
<Button
android:id="@+id/num2"
android:text="2"
style="@style/Button2"/>
<Button
android:id="@+id/num0"
android:text="0"
style="@style/Button2"/>
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
Name: Chaitra.M
Reg No: 9824037018
android:orientation="vertical">

<Button
android:id="@+id/ac"
android:text="AC"
style="@style/Button1"/>
<Button
android:id="@+id/num9"
android:text="9"
style="@style/Button2"/>
<Button
android:id="@+id/num6"
android:text="6"
style="@style/Button2"/>
<Button
android:id="@+id/num3"
android:text="3"
style="@style/Button2"/>
<Button
android:id="@+id/point"
android:text="."
style="@style/Button2"/>
</LinearLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<Button
android:id="@+id/div"
android:text="/"
style="@style/Button1"/>
<Button
android:id="@+id/times"
android:text="x"
style="@style/Button1"/>
<Button
android:id="@+id/min"
android:text="-"
style="@style/Button1"/>
<Button
android:id="@+id/plus"
android:text="+"
style="@style/Button1"/>
Name: Chaitra.M
Reg No: 9824037018
<Button
android:id="@+id/equal"
android:text="="
style="@style/Button1"/>

</LinearLayout>
</LinearLayout>
</RelativeLayout>

Calculator page activity code: MainActivity.java

package com.example.calculator;

import android.os.Bundle; import


android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {


double firstNum;
String operation;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Number Buttons
Button num0 = findViewById(R.id.num0);
Button num1 = findViewById(R.id.num1);
Button num2 = findViewById(R.id.num2);
Button num3 = findViewById(R.id.num3);
Button num4 = findViewById(R.id.num4);
Button num5 = findViewById(R.id.num5);
Button num6 = findViewById(R.id.num6);
Button num7 = findViewById(R.id.num7);
Button num8 = findViewById(R.id.num8);
Button num9 = findViewById(R.id.num9);

// Operation Buttons
Button on = findViewById(R.id.on);
Button off = findViewById(R.id.off);
Name: Chaitra.M
Reg No: 9824037018
Button ac = findViewById(R.id.ac);
Button del = findViewById(R.id.del);
Button div = findViewById(R.id.div);
Button times = findViewById(R.id.times);
Button min = findViewById(R.id.min);
Button equal = findViewById(R.id.equal);
Button plus = findViewById(R.id.plus);
Button point = findViewById(R.id.point);

// Screen (TextView)
TextView screen = findViewById(R.id.screen);

// AC Button (Clear all)


ac.setOnClickListener(view -> {
firstNum = 0;
screen.setText("0");
});

// OFF Button (Hide screen)


off.setOnClickListener(view -> screen.setVisibility(TextView.GONE));

// ON Button (Show screen and reset display)


on.setOnClickListener(view -> {
screen.setVisibility(TextView.VISIBLE);
screen.setText("0");
});

// Number button listeners


ArrayList<Button> nums = new ArrayList<>();
nums.add(num0); nums.add(num1);
nums.add(num2); nums.add(num3);
nums.add(num4); nums.add(num5);
nums.add(num6);
nums.add(num7);
nums.add(num8); nums.add(num9);

for (Button b : nums) {


b.setOnClickListener(view -> { if (!
screen.getText().toString().equals("0")) {
// Corrected string appending logic
screen.setText(screen.getText().toString() + b.getText().toString());
} else {
screen.setText(b.getText().toString());
}
});
Name: Chaitra.M
Reg No: 9824037018
}

// Operation button listeners


ArrayList<Button> opers = new ArrayList<>();
opers.add(div); opers.add(times);
opers.add(plus); opers.add(min);

for (Button b : opers) {


b.setOnClickListener(view -> { firstNum =
Double.parseDouble(screen.getText().toString());
operation = b.getText().toString();
screen.setText("0");
});
}

// Delete (DEL) button


del.setOnClickListener(view -> { String
num = screen.getText().toString();
if (num.length() > 1) {
screen.setText(num.substring(0, num.length() - 1));
} else if (num.length() == 1 && !num.equals("0")) {
screen.setText("0");
}
});

// Decimal point button


point.setOnClickListener(view -> { if (!
screen.getText().toString().contains(".")) {
screen.setText(screen.getText().toString() + "."); }
});

// Equal button to calculate result


equal.setOnClickListener(view -> {
double secondNum = Double.parseDouble(screen.getText().toString());
double result; switch (operation) { case "/":
if (secondNum != 0) {
result = firstNum / secondNum;
} else {
result = 0; // Handle divide by zero case
screen.setText("Error");
return;
}
break;
case "X":
Name: Chaitra.M
Reg No: 9824037018
result = firstNum * secondNum;
break; case "+":
result = firstNum + secondNum;
break; case "-":
result = firstNum - secondNum;
break; default:
result = firstNum + secondNum;
}
screen.setText(String.valueOf(result));
firstNum = result;
});
}

Calculator page activity code: AndroidManiFest.xml

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


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

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CalacutorProject"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

Calculator page activity code: Shape1.xml

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


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/orange"/>
Name: Chaitra.M
Reg No: 9824037018
Calculator page activity code: Shape2.xml

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


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/white"/>
</shape>

Calculator page activity code: Values\themes.xml

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.CalacutorProject"
parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
]
<item name="colorOnPrimary">@color/white</item>
<!-- secondary brand color-->
<item name="colorOnSecondary">@color/Black</item>
<!-- Status bar color -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
</style>
<style name="Button1">
<item name="android:layout_width">75dp</item>
<item name="android:layout_height">75dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">27dp</item>
<item name="android:gravity">center</item>
<item name="android:padding">10dp</item>
<item name="android:layout_margin">10dp</item>
<item name="android:background">@drawable/shape1</item>
</style>
<style name="Button2">
<item name="android:layout_width">75dp</item>
<item name="android:layout_height">75dp</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">27dp</item>
<item name="android:gravity">center</item>
<item name="android:padding">10dp</item>
<item name="android:layout_margin">10dp</item>
<item name="android:background">@drawable/shape2</item>
</style>
</resources>

Calculator page activity code: night\themes.xml


Name: Chaitra.M
Reg No: 9824037018
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <style
name="Theme.Calaclurproject"
parent="Theme.Material3.DayNight.NoActionBar">

<item name="colorPrimary">@color/Black</item>
<item name="colorPrimaryVariant">@color/Black</item>
<item name="colorOnPrimary">@color/Black</item>

<item name="colorSecondary">@color/Black</item>
<item name="colorSecondaryVariant">@color/Black</item>
<item name="colorOnSecondary">@color/Black</item>

<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>

</style>
</resources>

Calculator page activity code: colors.xml

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


<resources>
<color name="orange">#FFA500</color>
<color name="Black">#FF000000</color>
<color name="white">#FFFFFFFF</color> </resources>

Output:
Name: Chaitra.M
Reg No: 9824037018

Result:

Thus to native calculator was developed using Android Studio and the output was
verified.
Name: Chaitra.M
Reg No: 9824037018

Ex. No.4 Develop An Android Application To Create A Flashlight App

Date:

Aim:

To Develop an android application to create a flashlight app

Procedure

Step 1: Form design

1. Create new project.

2. Click res directory -> layout -> activity_main.xml -> Design

3. Insert three TextView control. Give the id property as “textViewLogin”,


“textViewName” and “textViewPassword” and give text property as “Login”,
“Username” and ”Password” respectively.

4. Insert two EditText control. Give the id as “editTextName” and “editTextPassword”


respectively.

5. Insert two Button control. Give the id as “buttonOk” and “buttonReset” and give text
property as “OK” and “Reset” respectively.

Step 2: Open java -> MainActivity.java and write the code needed for button “OK” and
“Reset” event triggering (refer program).

Step 3: Run the program using following steps in Android Emulator.


Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.

Program:
Name: Chaitra.M
Reg No: 9824037018
Design view code file name: activity main.xml

<?xmlversion="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/flashlightButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:src="@drawable/off" />

</RelativeLayout>

Calculator page activity code: MainActivity.java

import android.hardware.camera2.CameraAccessException; import


android.hardware.camera2.CameraManager;
import android.os.Bundle; import
android.widget.ImageView; import
android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private boolean isFlashlightOn = false;


private CameraManager cameraManager;
private String cameraId;
private ImageView flashlightButton;

@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

flashlightButton = findViewById(R.id.flashlightButton);

cameraManager = (CameraManager) getSystemService(CAMERA_SERVICE);


try {
cameraId = cameraManager.getCameraIdList()[0]; // Usually the back camera
} catch (CameraAccessException e)
{ e.printStackTrace();
}
Name: Chaitra.M
Reg No: 9824037018

flashlightButton.setOnClickListener(v -> {
try {
if (isFlashlightOn)
{ turnOffFlashlight();
} else {
turnOnFlashlight();
}
} catch (CameraAccessException e)
{ e.printStackTrace();
}
});
}

private void turnOnFlashlight() throws CameraAccessException {


if (cameraId != null) {
cameraManager.setTorchMode(cameraId, true);
isFlashlightOn = true;
flashlightButton.setImageResource(R.drawable.on); // Change image to 'on'
Toast.makeText(this, "Flashlight is ON", Toast.LENGTH_SHORT).show();
}
}

private void turnOffFlashlight() throws CameraAccessException {


if (cameraId != null) {
cameraManager.setTorchMode(cameraId, false);
isFlashlightOn = false;
flashlightButton.setImageResource(R.drawable.off); // Change image to 'off'
Toast.makeText(this, "Flashlight is OFF", Toast.LENGTH_SHORT).show();
}
}

Flashlight page activity code: AndroidManiFest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.FLASHLIGHT" />
Name: Chaitra.M
Reg No: 9824037018

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Flashlight"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

Output:
Name: Chaitra.M
Reg No: 9824037018

Flashlight is OFF Flashlight is ON

Result:

Thus to create flashlight app was developed using Android Studio and the output was
verified.
Name: Chaitra.M
Reg No: 9824037018
Ex. No.5 Develop An Android Application To Create A Sending Email

Date:

Aim:

To Develop an android application to create a sending email

Procedure

Step 1: Form design

1. Create new project.

2. Click res directory -> layout -> activity_main.xml -> Design

3. Insert three TextView control. Give the id property as “textViewLogin”,


“textViewName” and “textViewPassword” and give text property as “Login”,
“Username” and ”Password” respectively.

4. Insert two EditText control. Give the id as “editTextName” and “editTextPassword”


respectively.

5. Insert two Button control. Give the id as “buttonOk” and “buttonReset” and give text
property as “OK” and “Reset” respectively.

Step 2: Open java -> MainActivity.java and write the code needed for button “OK” and
“Reset” event triggering (refer program).

Step 3: Run the program using following steps in Android Emulator.


Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.

Program:

Design view code file name: activity main.xml


Name: Chaitra.M
Reg No: 9824037018
<?xml version="1.0" encoding="utf-8"?>
<!-- Relative Layout -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<!-- Edit text for email id -->


<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="22dp" />

<!-- Edit text for email subject -->


<EditText android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp" />

<!-- Edit text for email body -->


<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginTop="30dp" />

<!-- text Views for label -->


<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editTe
xt1"
android:layout_alignBottom="@+id/editTex
t1"
Name: Chaitra.M
Reg No: 9824037018
android:layout_alignParentLeft="true"
android:text="Send To:"
android:textColor="#0F9D58" />

<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="Email Subject:"
android:textColor="#0F9D58" />

<TextView android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
android:text="Email Body:"
android:textColor="#0F9D58" />

<!-- Button to send email -->


<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:text="Send email!!" />
</RelativeLayout>

Email page activity code: MainActivity.java package


com.example.email; import android.content.Intent;
import android.os.Bundle; import
android.widget.Button; import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// define objects for edit text and button
Button button;
EditText sendto, subject, body;
Name: Chaitra.M
Reg No: 9824037018
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // Getting
instance of edittext and button sendto =
findViewById(R.id.editText1); subject =
findViewById(R.id.editText2); body =
findViewById(R.id.editText3); button =
findViewById(R.id.button);
// attach setOnClickListener to button with Intent object define in it
button.setOnClickListener(view -> {
String emailsend = sendto.getText().toString();
String emailsubject = subject.getText().toString();
String emailbody = body.getText().toString();
// define Intent object with action attribute as ACTION_SEND
Intent intent = new Intent(Intent.ACTION_SEND);
// add three fields to intent using putExtra function
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailsend});
intent.putExtra(Intent.EXTRA_SUBJECT, emailsubject);
intent.putExtra(Intent.EXTRA_TEXT, emailbody);
// set type of intent
intent.setType("message/rfc822");
// startActivity with intent with chooser as Email client using createChooser function
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
});
}}

Output:
Name: Chaitra.M
Reg No: 9824037018

Result:

Thus to create sending email was developed using Android Studio and the output
was verified.
Name: Chaitra.M
Reg No: 9824037018
Ex. No.6 Develop An Android Application To Create A Sending SMS

Date:

Aim:

To Develop an android application to create a sending SMS

Procedure

Step 1: Form design

1. Create new project.

2. Click res directory -> layout -> activity_main.xml -> Design

3. Insert three TextView control. Give the id property as “textViewLogin”,


“textViewName” and “textViewPassword” and give text property as “Login”,
“Username” and ”Password” respectively.

4. Insert two EditText control. Give the id as “editTextName” and “editTextPassword”


respectively.

5. Insert two Button control. Give the id as “buttonOk” and “buttonReset” and give text
property as “OK” and “Reset” respectively.

Step 2: Open java -> MainActivity.java and write the code needed for button “OK” and
“Reset” event triggering (refer program).

Step 3: Run the program using following steps in Android Emulator.


Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.

Program:

Design view code file name: activity main.xml


Name: Chaitra.M
Reg No: 9824037018
<?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:orientation="vertical"
android:gravity="center" android:padding="15dp"
tools:context=".MainActivity">

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:id="@+id/editText1"
android:padding="15dp"
android:maxLength="10"
android:inputType="phone"
android:background="@drawable/rect"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Enter Phone Number"
android:padding="15dp"
android:maxLength="20"
android:inputType="textMultiLine"
android:lines="7"
android:background="@drawable/rect"
android:layout_marginTop="15dp"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnSent"
android:text="Sending SMS"
android:layout_marginTop="30dp"/> Sending
SMS page activity code: rect.xml

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


<shape xmlns:android="http://schemas.android.com/apk/res/android">
android:shape="rectangle"> <solid android:color="@color/white"/>
<stroke android:width="1dp"
android:color="@color/black"/>
<corners android:radius="5dp"/>
</shape>
Name: Chaitra.M
Reg No: 9824037018
Sending SMS page activity code: MainActivity.java

package com.example.sms;

import android.Manifest; import


android.annotation.SuppressLint; import
android.content.pm.PackageManager; import
android.os.Bundle; import
android.telephony.SmsManager; import
android.view.View; import
android.widget.Button; import
android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge; import


androidx.annotation.NonNull; import
androidx.annotation.ReturnThis; import
androidx.appcompat.app.AppCompatActivity; import
androidx.core.app.ActivityCompat; import
androidx.core.content.ContextCompat; import
androidx.core.graphics.Insets; import
androidx.core.view.ViewCompat; import
androidx.core.view.WindowInsetsCompat;
import kotlin.Suppress;
import kotlinx.coroutines.flow.internal.SendingCollector;

public class MainActivity extends AppCompatActivity {

EditText editTextPhone, editTextMessage;


Button btnsent;

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

editTextPhone = findViewById(R.id. editText1);


editTextMessage = findViewById(R.id.editText);
btnsent = findViewById(R.id.btnSent);

btnsent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ContextCompat.checkSelfPermission(MainActivity.this,
Name: Chaitra.M
Reg No: 9824037018
Manifest.permission.SEND_SMS)
== PackageManager.PERMISSION_GRANTED) {
sendSMS();
} else {
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{Manifest.permission.SEND_SMS},
100);
}
}
});
}

private void sendSMS() {


String phone = editTextPhone.getText().toString();
String message = editTextMessage.getText().toString();
;
if (!phone.isEmpty() && !message.isEmpty()) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phone, null, message, null, null);
Toast.makeText(this, "SMS Sent Successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Please enter phone snd message!!",
Toast.LENGTH_SHORT).show();
}
}}
Send
ing
SMS
page
activ
ity
code
:
And
roid
Man
ifest.
xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature android:name="android.permission.SEND_SMS"/>
<uses-feature
android:name="android.hardware.telephony"
Name: Chaitra.M
Reg No: 9824037018
android:required="false" />
<uses-permission android:name="android.permission.SEND_SMS" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SMS"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>

</manifest>

Output:
Name: Chaitra.M
Reg No: 9824037018

Result:

Thus to Create sending SMS was developed using Android Studio and the output
was verified.
Name: Chaitra.M
Reg No: 9824037018

Ex. No.7 Develop An Android Application To Create A Analog Dialog

Date:

Aim:

To Develop an android application to create a sending SMS

Procedure

Step 1: Form design

1. Create new project.

2. Click res directory -> layout -> activity_main.xml -> Design

3. Insert three TextView control. Give the id property as “textViewLogin”,


“textViewName” and “textViewPassword” and give text property as “Login”,
“Username” and ”Password” respectively.

4. Insert two EditText control. Give the id as “editTextName” and “editTextPassword”


respectively.

5. Insert two Button control. Give the id as “buttonOk” and “buttonReset” and give text
property as “OK” and “Reset” respectively.

Step 2: Open java -> MainActivity.java and write the code needed for button “OK” and
“Reset” event triggering (refer program).

Step 3: Run the program using following steps in Android Emulator.


Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.

Program:
Name: Chaitra.M
Reg No: 9824037018
Design view code file name: activity main.xml

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


<RelativeLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:gravity="center_horizontal"
android:text="Press The Back Button of Your Phone."
android:textSize="30dp" android:textStyle="bold" />

</RelativeLayout>

Analog Dialog page activity code: MainActivity.java

package com.example.alertdialog;

import android.content.DialogInterface;
import android.os.Bundle; import
androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("Do you want to exit ?");

builder.setTitle("Alert !");
builder.setCancelable(false);
builder.setPositiveButton("Yes",
Name: Chaitra.M
Reg No: 9824037018
(DialogInterface.OnClickListener) (dialog, which) -> {
finish();
});
builder.setNegativeButton("No", (DialogInterface.OnClickListener) (dialog, which) -> {
dialog.cancel();
});

AlertDialog alertDialog = builder.create();


alertDialog.show();
}
}

Output:

Result:

Thus to Create analog dialog was developed using Android Studio and the output
was verified.
Name: Chaitra.M
Reg No: 9824037018

Ex. No.8 Develop An Android Application To Create A Splash Screen

Date:

Aim:

To Develop an android application to create a splash screen

Procedure

Step 1: Form design

1. Create new project.

2. Click res directory -> layout -> activity_main.xml -> Design

3. Insert three TextView control. Give the id property as “textViewLogin”,


“textViewName” and “textViewPassword” and give text property as “Login”,
“Username” and ”Password” respectively.

4. Insert two EditText control. Give the id as “editTextName” and “editTextPassword”


respectively.

5. Insert two Button control. Give the id as “buttonOk” and “buttonReset” and give text
property as “OK” and “Reset” respectively.

Step 2: Open java -> MainActivity.java and write the code needed for button “OK” and
“Reset” event triggering (refer program).

Step 3: Run the program using following steps in Android Emulator.


Select the project in Package Explorer and Click Run icon in the tool bar.
(or)
Click Run in the menu bar and choose Run option.
(or)
Right-click the project in the Package Explorer, select “Run As” menu and click “Android
Application” menu.
Name: Chaitra.M
Reg No: 9824037018

Program:

Design view code file name: activity main.xml

You might also like