0% found this document useful (0 votes)
27 views

Mad Manul

The document provides instructions for installing and configuring the Java Development Kit (JDK), Android Studio, and creating an Android Virtual Device on Windows. The key steps include: 1. Downloading and installing the latest JDK from Oracle's website. 2. Configuring environment variables to specify the JDK file location. 3. Downloading and installing Android Studio and SDK from the Android developer website. 4. Installing the Android Development Tools plugin for Eclipse. 5. Using the AVD Manager in Android Studio to create a virtual Android device for testing applications.
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)
27 views

Mad Manul

The document provides instructions for installing and configuring the Java Development Kit (JDK), Android Studio, and creating an Android Virtual Device on Windows. The key steps include: 1. Downloading and installing the latest JDK from Oracle's website. 2. Configuring environment variables to specify the JDK file location. 3. Downloading and installing Android Studio and SDK from the Android developer website. 4. Installing the Android Development Tools plugin for Eclipse. 5. Using the AVD Manager in Android Studio to create a virtual Android device for testing applications.
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/ 143

Practical No.

1: Compare various operating systems with


Android OS.

Required :-

Sr. Instrument /Object Specification Quantity


No.
Computer Operating (i3-i5) 1
1. System Ram 8 GB
Ssd 512
2. Software Android 1
Studio

Theroy:
Operating system basics like definition of operating systems, features
of operating systems. What is the need of operating systems? Basic
architecture of operating systems. Different types of operating
systems. Distinguishing points between different operating systems.
Android is an open source and Linux-based Operating System for
mobile devices such as smartphones and tablet computers. Android
was developed by the Open Handset Alliance, led by Google, and
other companies. Android offers a unified approach to application
development for mobile devices which means developers need to
develop only for Android, and their applications should be able to run
on different devices powered by Android.

1
1. List different Android O.S. versions.
:= Following are Android O.S. versions :-
o Cupcake 1.5
o Donut 1.6
o Éclair 2.0 – 2.1
o Gingerbread 2.3 – 2.3.7
o Honeycomb 3.0 – 3.2.6
o Icecream Sandwich 4.0 – 4.0.4
o Jelly Bean 4.1 – 4.4.4
o Lollipop 5.0 – 5.1.1
o Marshmallow 6.0 – 6.0.1
o Nougat 7.0
o Oreo 8.0
o Pei 9.0
o Android 10 10.0
o Android 11 11

2. State characteristics of android operating system


:= Feature of Android Operating System
o Near Field Communication
o Alternate Keyboards
o IR Transmission
o No-Touch Control
o Automation
o Wireless App Downloads
o Storage & Battery Swap
o Custom Home Screen
o Widgets
o Custom ROMs
o Headset layout

2
3. Draw the architectural diagram of Android operating system.

4. Differentiate between Windows operating system and Android


operating system.

3
4
Practical No. 2: Install and configure java development
kit (JDK), Android studio and android SDK.

Required :-
Sr. Instrument /Object Specification Quantity
No.
Computer Operating (i3-i5) 1
1. System Ram 8 GB
Ssd 512
2. Software Android 1
Studio

Theory :
Step 1 - Setup Java Development Kit (JDK) You can download
the latest version of Java JDK from Oracle's Java site: Java SE
Downloads. You will find instructions for installing JDK in
downloaded files, follow the given instructions to install and
configure the setup. Finally, set PATH and JAVA_HOME
environment variables to refer to the directory that contains java
and javac, typically java_install_dir/bin and java_install_dir
respectively. If you are running Windows and have installed the
JDK in C:\jdk1.6.0_15, you would have to put the following line
in your C:\autoexec.batfile. set
PATH=C:\jdk1.6.0_15\bin;%PATH% set
JAVA_HOME=C:\jdk1.6.0_15
Step 2 - Setup Android SDK You can download the latest
version of Android SDK from Android’s official website:
http://developer.android.com/sdk/index.html. If you are
installing SDK on Windows machine, then you will find
ainstaller_rXXwindows.exe, so just download and run this exe
which will launch Android SDK Tool Setup wizard to guide you
throughout the installation, so just follow the instructions
5
carefully. Finally, you will have Android SDK Tools installed on
your machine. If you are installing SDK either on Mac OS or
Linux, check the instructions provided along with the
downloaded android-sdk_rXX-macosx.zip file for Mac OS and
androidsdk_rXX-linux.tgz file for Linux. This tutorial will
consider that you are going to setup your environment on
Windows machine having Windows 7 operating system.
Step 3 - Setup Android Development Tools (ADT) Plugin This
step will help you in setting Android Development Tool plugin
for Eclipse. Let's start with launching Eclipse and then, choose
Help > Software Updates > Install New Software. This will
display the following dialogue box.
Step 4 - Create Android Virtual Device to test your Android
applications you will need a virtual Android device. So before
we start writing our code, let us create an Android virtual
device. Launch Android AVD Manager using Eclipse menu
options Window > AVD Manager> which will launch Android
AVD Manager. Use New button to create a new Android Virtual
Device and enter the following information, before clicking
Create AVD button.

1. Install & Configure Java development key and Android SDK


:= Step 1: Download and Install Java Development Kit (JDK)
The very first step is to download the Oracle Java Development Kit
(JDK) from the Official Oracle Website.

6
You need to identify your system specifications to choose the
Product/file description. The website will contain the latest version for
your corresponding system. For Windows, we’ll be downloading the
latest x64 Installer of Java SE Development Kit 18. After the download
is complete, proceed to install the JDK by following the bootstrapped
steps.

Step 2: Configure Environment Variables


After the installation is complete, we have to configure environment variables to
notify the system about the directory in which JDK files are located. Proceed
to C:\Program Files\Java\jdk-{YOUR_JDK_VERSION}\bin (replace {-} with
your JDK version)

7
To set the Environment Variables, you need to search Environment Variables in
the Task Bar and click on “Edit the system environment variables”.

8
Under the Advanced section, Click on “Environment Variables”.

Under System variables, select the “Path” variable and click on “Edit”. Click
on “New” then paste the Path Address i.e. C:\Program Files\Java\jdk-
{YOUR_JDK_VERSION}\bin. Click on “OK”.

Now, in the Environment Variables dialogue, under System variables, click


on “New” and then under Variable name: JAVA_HOME and Variable
value: paste address i.e. C:\Program Files\Java\jdk-{YOUR_JDK_VERSION}.
Click on OK => OK => OK.

9
Step 3: Check the Java Version
Open Command Prompt and enter the following commands
java -version
javac -version

10
2. Difference between JVM & DVM
:=
DVM (Delvik Virtual Machine) JVM (Java Virtual Machine)
It is Register based which is It is stack based.
Designed to run on low memory.
DVM support Android Operating JVM support Multiple Operating
system only. systems.
For DVM very few Re-tools are For JVM Re-tools are Available
Available
There is constant pool for every It has constant pool for every class.
application

11
Practical No. 3: Configure android development tools (ADT)
plug-in and create android virtual device.

Q1.List basic requirements for configuring android operating system?


The basic requirements for configuring the Android operating system
will depend on whether you're talking about configuring an Android
device itself or configuring a development environment to build the
Android Open Source Project (AOSP). Here's a breakdown for both
scenarios:

Configuring an Android device:


Hardware: Android runs on a wide range of devices with varying
specifications. However, most modern devices will have at least:
64-bit processor (typically ARM-based)
2GB RAM (more is recommended)
16GB storage (more is recommended)
Wi-Fi and Bluetooth connectivity

Software:
A compatible version of the Android operating system (varies
depending on the device)
Google Play Store or other app store for downloading apps
Configuring a development environment (AOSP):

Operating system:
64-bit Windows, macOS, or Linux
12
Hardware:
Powerful CPU (preferably 64-core or more)
Minimum 16GB RAM (64GB or more recommended)
Minimum 250GB free disk space (additional space needed for builds)
High-resolution display (1280 x 800 minimum)

2.Why byte code cannot run in Android


While Android apps are developed using Java, standard Java bytecode
cannot directly run on Android devices for several key reasons:

1. Distinct Virtual Machines:


Android uses Dalvik Virtual Machine (DVM) or Android Runtime
(ART): These virtual machines are specifically designed for resource-
constrained mobile environments, prioritizing efficiency and
performance.
Standard Java bytecode runs on Java Virtual Machine (JVM): JVM is
optimized for desktop and server platforms, with different architecture
and memory management.
2. Bytecode Format Differences:
DVM/ART bytecode is not identical to JVM bytecode: It's optimized
for mobile devices, with smaller size, different instructions, and
memory usage patterns.
3. Class Library Incompatibilities:
Android uses a distinct set of core libraries (Android SDK): These are
tailored for mobile development and differ from the standard Java
libraries.
Addressing the Issue:
13
Android build tools convert Java bytecode to Dalvik Executable
(DEX) format: This process ensures compatibility with DVM/ART.
DEX files are optimized for mobile: They use shared memory for
common code elements, reducing app size and memory footprint.
Key Points:
Specific virtual machines and bytecode formats: Android's choice of
VMs and bytecode optimization is crucial for its performance on
resource-constrained devices.
Build tools handle conversion: Android development tools automate
the conversion process, making it seamless for developers.
Additional Context:
Evolution of Android runtimes:
DVM was the initial runtime: It used a process called "just-in-time"
(JIT) compilation to interpret bytecode at runtime.
ART was introduced in Android 4.4: It pre-compiles bytecode during
app installation, improving performance and reducing startup time.
In essence, while Android apps are written in Java, they undergo a
transformation process to ensure compatibility with the specific
runtime environment of Android devices, ensuring optimal
performance and resource utilization on mobile platforms.

3.Explain the build process in android


The Android build process can seem complex, but it's essentially
transforming your source code into an app that can run on a device.
Here's a breakdown of the key steps:

1. Setting Up the Environment:

14
Install the Android SDK and configure the build environment by
setting up paths and variables.
Choose a target device or emulator to build for.
2. Processing Resources:
The Android Asset Packaging Tool (AAPT) processes all resources
like layouts, images, and strings in the res/ directory.
It generates an R.java file containing resource IDs and compiles other
resources into a binary format.
3. Compiling Java Code:
Java source code gets compiled into .class files using the javac
compiler.
These .class files are further converted into Dalvik bytecode (.dex
files) compatible with the Android virtual machine (Dalvik VM).
4. Assembling the APK:
The processed resources and .dex files are combined with the Android
Manifest (AndroidManifest.xml) file, which defines app metadata.
This creates an .apk file, the installable app package.
5. Signing and Releasing:
Debug builds are automatically signed for testing using a debug key.
For release builds, you need to sign the app with a release key to
ensure its authenticity and integrity.

4.Write steps to create Android virtual device

15
Creating an Android Virtual Device (AVD)
An AVD lets you simulate a specific Android device on your
computer, perfect for testing and developing your apps. Here's how to
create one in Android Studio:

1. Open the AVD Manager:


Go to Tools > AVD Manager.
2. Create a New AVD:
Click Create Virtual Device.
3. Choose a Hardware Profile:
Select a device category (Phone, Tablet, etc.) and model.
Consider your target audience and app requirements.
Click Next.
4. Select a System Image:
Choose an Android API level (version) to emulate.
Download the required system image.
If unavailable, click **Show Packages **to install required SDK
platforms.
Click Next.
5. Configure AVD Details:
Name your AVD (e.g., Pixel 6 Pro, Android 13).
Set internal storage size (default is 2048 MiB).
Optionally, configure RAM, CPU cores, and other advanced settings.
Click Finish.

6. (Optional) Launch the AVD:


16
Select your newly created AVD from the list.
Click Start.
The emulator will launch, simulating your chosen device.

Tips:
You can duplicate existing AVDs for quick variations.
Adjust resource allocation if your computer struggles with emulation.
Configure additional options like sensors, camera, and SD card in the
AVD configuration window.
Remember to download necessary Google Play services for full
functionality.
Alternatives:
If you don't have Android Studio, use the online tool Android
Emulator in Web.
By following these steps, you can create an AVD that emulates the
desired Android device for testing and development, making your
Android app journey smoother.

17
Practical No. 4: Development a Program to display Hellow
World on screen

Activity_main.xml

MainActivity.java

Output:-
18
19
Practical No 5: Development a Program to important Linear
layout and Absolute layout

LINEAR LAYOUT
Activity_main.xml

20
MainActivity.java

Output:-

21
Absolute Layout
Activity_main.xml

22
MainActivity.java

23
Output:-

24
Practical No 6:- Develop a program to implement frame
layout, table layout and relative layout

Frame Layout :-

25
Output :-

26
Table layout :-

27
28
29
Output :-

30
Practical No 7:- Develop a program to implement Text View
and Edit Text

Write a program to accept username and password from the end user using Text
View and Edit Text.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username:"
android:textSize="25sp"
android:id="@+id/textViewUsername"
android:layout_marginBottom="500dp"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:id="@+id/editTextUsername"
android:layout_below="@id/textViewUsername"
android:layout_marginBottom="500dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:textSize="25sp"
android:id="@+id/textViewPassword"
android:layout_below="@id/editTextUsername"
android:layout_marginTop="16dp
android:layout_marginBottom="8dp"/>

31
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content
" android:inputType="textPassword" android:id="@+id/editTextPassword"
android:layout_below="@id/textViewPassword"
android:layout_marginBottom="500dp"/>

<Button
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/buttonSubmit"
android:layout_below="@id/editTextPassword"
android:layout_centerHorizontal="true"
android:layout_marginTop="500dp"/>

</RelativeLayout>

Output :-

32
Write a program to accept and display personal information of student

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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/btnorg"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:fontFamily="sans-serif"
android:padding="20dp"
android:text=" Enter your personal information "
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/whiteb"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif"
android:text=" Fill the Form "
android:textSize="25dp"
android:textAlignment="center"
android:textStyle="bold" />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
33
android:hint="Name :"
android:layout_marginLeft="20dp"
android:id="@+id/name"
android:layout_marginRight="20dp"
android:textSize="20dp"
></EditText>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Date of Birth :"
android:id="@+id/dob"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:inputType="date"
android:textSize="20dp"
></EditText>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:id="@+id/ct"
android:layout_marginRight="20dp"
android:hint="City :"
android:textSize="20dp"
></EditText>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:id="@+id/mob"
android:layout_marginRight="20dp"
android:hint="Mobile number :"
android:inputType="number"
android:textSize="20dp"
></EditText>
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
></TextView>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"

34
android:text="SUBMIT"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="@drawable/btnblue"
android:layout_marginTop="-20dp"
android:id="@+id/submit"
></Button>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Student Information"
android:textSize="20dp"
android:textAlignment="center"
android:layout_marginTop="20dp"
></TextView>
<TextView
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:id="@+id/dn"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:textSize="15dp"
android:padding="10dp"
></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/dd"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:padding="10dp"
android:textSize="15dp"
></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:padding="10dp"
android:id="@+id/dc"
android:textSize="15dp"></TextView>

35
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:textSize="15dp"
android:padding="10dp"
android:id="@+id/dm"
></TextView>
</LinearLayout>

MainActivity.java:-

package com.example.ashish;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText n,dateob,city,mob;
TextView disn,disd,disc ,dism;
Button sbt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
n=findViewById(R.id.name);
dateob=findViewById(R.id.dob);
city=findViewById(R.id.ct);
mob=findViewById(R.id.mob);
sbt=findViewById(R.id.submit);
disn=findViewById(R.id.dn);
disd=findViewById(R.id.dd);
disc=findViewById(R.id.dc);
dism=findViewById(R.id.dm);
sbt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
disn.setText("Name :"+n.getText().toString());
disd.setText("Date of Birth

36
:"+dateob.getText().toString());
disc.setText("City :"+city.getText().toString());
dism.setText("Mobile number
:"+mob.getText().toString());
}
});
}
}

Output :-

37
Practical 8 :- Develop a program to implement AutoComplete Text
View

Q1. Write a program to create a first display screen of any search


engine using Auto Complete Text View .

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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/btnorg"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter A search engine name"
android:textAlignment="center"
android:padding="20dp"
android:textSize="25dp"
android:textStyle="bold"
android:layout_marginTop="270dp"
></TextView>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search"
android:layout_marginLeft="20dp"
android:id="@+id/search"
android:layout_marginRight="20dp"
android:textSize="20dp"
></AutoCompleteTextView>
</LinearLayout>

38
MainActivity.java
❖ package com.example.ashish;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
String[]
str={"Google","Yahoo","Brave","wiki","AOL","Baidu","Ecosia","you
tube"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item,str);
AutoCompleteTextView actv=findViewById(R.id.search);
actv.setThreshold(1);
actv.setAdapter(adapter);
}
}

39
Output :-

40
Q2. Write a program to display all the subjects of sixth semester using
Auto Complete Text View .

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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/btnorg"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter a 6th semester subject "
android:textAlignment="center"
android:padding="20dp"
android:textSize="25dp"
android:textStyle="bold"
android:layout_marginTop="270dp"
></TextView>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search"
android:layout_marginLeft="20dp"
android:id="@+id/search"
android:layout_marginRight="20dp"
android:textSize="20dp"
></AutoCompleteTextView>
</LinearLayout>

41
MainActivity.java

package com.example.ashish;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
String[] str={"EDE","ETI","MGT","PWP","MAD","NIS"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item,str);
AutoCompleteTextView actv=findViewById(R.id.search);
actv.setThreshold(1);
actv.setAdapter(adapter);
}
}

42
Output :-

43
Practical 9 :- Develop a program to implement Button, Image Button
and Toggel Button.

Q1. Write a program to create a toggle button to display ON / OFF


Bluetooth on the display screen .

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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/btnorg"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginTop="100dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/whiteb"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bluetooth OFF"
android:textAlignment="center"
android:textStyle="bold"
android:textSize="25dp"
android:id="@+id/text1"
></TextView>

44
<ToggleButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:id="@+id/tgbtn"
>
</ToggleButton>
</LinearLayout>
</LinearLayout>

MainActivity.java

package com.example.;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
ToggleButton tb;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tb = findViewById(R.id.tgbtn);
tv = findViewById(R.id.text1);
tb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (tb.isChecked()) {
tv.setText("Bluetooth ON");
} else {

45
tv.setText("Bluetooth OFF");
}
}
});
}
}

Output :-

46
2. Write a program to create a simple calculator .
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/btnorg"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="30dp"
android:layout_marginTop="00dp"
android:textSize="30dp"
android:text="Simple Calculator"
android:textAlignment="center"
android:textStyle="bold"
></TextView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"
android:layout_marginRight="20dp"
android:background="@drawable/whiteb"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="30dp"
android:layout_marginTop="00dp"
android:id="@+id/sol"
android:textSize="30dp"
android:text="sol"
android:textStyle="bold"
android:textAlignment="textEnd"
></TextView>
</LinearLayout>
47
<LinearLayout
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/whiteb"
android:orientation="vertical"
>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TableRow
android:padding="7dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:background="@drawable/btnblue"
android:text="1"
android:id="@+id/d1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/btnblue"
android:text="2"
android:id="@+id/d2"
/>

48
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/btnblue"
android:text="3"
android:id="@+id/d3"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/orgbtn"
android:text="+"
android:id="@+id/add"
/>
</TableRow>
<TableRow
android:padding="7dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:id="@+id/d4"
android:padding="25dp"
android:background="@drawable/btnblue"
android:text="4"
/>
<TextView
android:layout_width="wrap_content"

49
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/btnblue"
android:text="5"
android:id="@+id/d5"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/btnblue"
android:text="6"
android:id="@+id/d6"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/orgbtn"
android:text="-"
android:id="@+id/sub"
/>
</TableRow>
<TableRow
android:padding="7dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

50
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:background="@drawable/btnblue"
android:text="7"
android:id="@+id/d7"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/btnblue"
android:text="8"
android:id="@+id/d8"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/btnblue"
android:text="9"
android:id="@+id/d9"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/orgbtn"
android:text="*"
android:id="@+id/mul"
/>
</TableRow>
<TableRow
android:padding="7dp"

51
android:layout_marginLeft="20dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:background="@drawable/orgbtn"
android:text="7"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/btnblue"
android:text="0"
android:id="@+id/d0"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"
android:background="@drawable/orgbtn"
android:text="9"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textStyle="bold"
android:padding="25dp"
android:layout_marginLeft="20dp"

52
android:background="@drawable/orgbtn"
android:text="="
android:id="@+id/equ"
/>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>

❖ MainActivity.java
❖ package com.example.tanmay;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
TextView n1,n2,n3,n4,n5,n6,n7,n8,n9,n0,solu,add,equ,sub,mul;
String str="" ,str2="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
n1=findViewById(R.id.d1);
n2=findViewById(R.id.d2);
n3=findViewById(R.id.d3);
n4=findViewById(R.id.d4);
n5=findViewById(R.id.d5);
n6=findViewById(R.id.d6);
n7=findViewById(R.id.d7);
n8=findViewById(R.id.d8);
n9=findViewById(R.id.d9);
n0=findViewById(R.id.d0);
add=findViewById(R.id.add);
sub=findViewById(R.id.sub);
equ=findViewById(R.id.equ);
solu=findViewById(R.id.sol);
n1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n1.getText().toString();
53
solu.setText(str);
}
});
n2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n2.getText().toString();
solu.setText(str);
}
});
n3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n3.getText().toString();
solu.setText(str);
}
});
n4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n4.getText().toString();
solu.setText(str);
}
});
n5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n5.getText().toString();
solu.setText(str);
}
});
n6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n6.getText().toString();
solu.setText(str);
}
});
n7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n7.getText().toString();
solu.setText(str);

54
}
});
n8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n8.getText().toString();
solu.setText(str);
}
});
n9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n9.getText().toString();
solu.setText(str);
}
});
n0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=n0.getText().toString();
solu.setText(str);
}
});
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=add.getText().toString();
solu.setText(str);
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
str+=sub.getText().toString();
solu.setText(str);
}
});
equ.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}

55
}
Output :-

56
Practical 10 :- Develop a program to Implement login window using
above UI control.

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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="Facebook"
android:textAlignment="center"
android:textStyle="bold"
android:textSize="40dp"
android:textColor="#1D38D1"
></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="LOGIN"
android:textAlignment="center"
android:textStyle="bold"
android:textSize="20dp"
android:textColor="#090909"
></TextView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username :"
android:textSize="20dp"
android:layout_marginLeft="50dp"

57
android:layout_marginRight="50dp"
android:id="@+id/uname"
android:layout_marginTop="30dp"
android:padding="15dp"
></EditText>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password :"
android:textSize="20dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="30dp"
android:padding="15dp"
android:id="@+id/pass1"
android:inputType="textPassword"
></EditText>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:padding="10dp"
android:text="Login"
android:background="@color/purple_700"
></Button>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="forgot password ?"
android:textAlignment="center"
android:textStyle="bold"
android:textColor="#1D38D1"
></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="-----------------------------OR----------------------
---------"
android:textAlignment="center"
android:textStyle="bold"

58
android:textColor="#69696E"
></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="Create New Facebook Account"
android:textAlignment="center"
android:padding="10dp"
android:layout_marginLeft="90dp"
android:layout_marginRight="90dp"
android:textStyle="bold"
android:background="#017A03"
android:textColor="@color/white"
></TextView>
</linearLayout>

59
Output:-

60
Practical 11:- Develop a program to implement CheckBox.

Practical No. 11:


1. Write a program to show five checkbox and toast selected
checkboxes
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="@drawable/btnorg"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@drawable/whiteb"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="150dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Select Your Subject "
android:textAlignment="center"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#1D38D1"
></TextView>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"

61
android:text="Java"
android:id="@+id/java"
></CheckBox>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Python "
android:id="@+id/python"
></CheckBox>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Client Side Scripting "
android:id="@+id/CSS"
></CheckBox>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="C++"
android:id="@+id/c"
></CheckBox>
<CheckBox
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PHP"
android:id="@+id/php"
></CheckBox>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:onClick="Check"
android:text="SUBmit"
></Button>
</LinearLayout>
</LinearLayout>

62
MainActivity.java
package com.example.tanmay;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
CheckBox java,python,css,php,c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
java = findViewById(R.id.java);
css = findViewById(R.id.CSS);
php = findViewById(R.id.php);
python = findViewById(R.id.python);
c = findViewById(R.id.c);
}
public void Check(View v)
{
String msg="";
if(java.isChecked())
msg = msg + " java ";
if(python.isChecked())
msg = msg + " python ";
if(css.isChecked())
msg = msg + " CSS ";
if(c.isChecked())
msg = msg + " C++ ";
if(php.isChecked())
msg = msg + " php ";
Toast.makeText(this, msg + "are selected",
Toast.LENGTH_LONG).show();
}

63
}
Output :-

64
2.Write a program to show the following output . First 2 radio button are
without radio group and next 2 buttons are using radio group.

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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="@drawable/btnorg"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:background="@drawable/whiteb"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="150dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Single Radion Buttons "
android:textAlignment="center"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#1D38D1"
></TextView>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button 1"
android:id="@+id/r1"
></RadioButton>

65
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button 2"
android:id="@+id/r2"
></RadioButton>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Radio button inside RadioGroup "
android:textAlignment="center"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#1D38D1"
></TextView>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gender">
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Male"
android:id="@+id/male"
></RadioButton>
<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Femail"
android:id="@+id/female"
></RadioButton>
></RadioGroup>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:onClick="Check"
android:text="SUBmit"

66
></Button>
</LinearLayout>
</LinearLayout>

MainActivity.java
package com.example.tanmay;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends AppCompatActivity {
RadioButton r1,r2,female,male;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
r1 = findViewById(R.id.r1);
r2 = findViewById(R.id.r2);
male = findViewById(R.id.male);
female = findViewById(R.id.female);
}
public void Check(View v)
{
String msg="";
String msg1="";
if(r1.isChecked())
msg = msg + " Radio 1 ";
if(r2.isChecked())
msg = msg + " Radio 2 ";
if(male.isChecked())
msg1 = msg1 + " male ";
if(female.isChecked())
msg1 = msg1 + " Female ";
Toast.makeText(this, "Single Radio Button :"+msg +" RadiobtnGroup :"+msg1 ,

67
Toast.LENGTH_LONG).show();
}
}
Output :-

68
Practical No 12:- Develop a program to implement Radio Button and
Radio Group.

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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="ProgressBar "
android:textAlignment="center"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#1D38D1"
></TextView>
<ProgressBar
android:layout_width="260dp"
android:layout_height="200dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="50dp"
android:progress="80"
android:progressDrawable="@drawable/circular"
></ProgressBar>
</LinearLayout>
-----res/ drawable/circular.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="ring"
xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="100dp"
android:thickness="10dp"
android:useLevel="true"
>

69
<solid android:color="#790D8B"/>
</shape>
❖ Output :
❖ Program Code :
❖ 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="ProgressBar Horizontol "
android:textAlignment="center"
android:textStyle="bold"
android:textSize="25dp"
android:textColor="#1D38D1"
></TextView>
<ProgressBar
android:id="@+id/simpleProgressBar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:max="100"
android:progress="50"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:progressDrawable="@drawable/circular" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Download"

70
android:layout_marginLeft="150dp"
android:layout_marginTop="50dp"
></Button>
</LinearLayout>

❖ res/ drawable/circular.xml :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#fff"
android:endColor="#1f1"
android:useLevel="true"
></gradient>
</shape>

71
Output :-

72
Practical No 13:- Develop a program to implement Progress Bar

1)Write a program to display circular progress bar.

➢activity_main.xml

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


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

<ProgressBar
android:id="@+id/horizontalProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:visibility="gone"/>

<TextView
android:id="@+id/percentageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/horizontalProgressBar"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="0%"/>

</RelativeLayout>

73
MainActivity.java

package com.example.mad;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{
private ProgressBar horizontalProgressBar;
private TextView percentageTextView;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
horizontalProgressBar = findViewById(R.id.horizontalProgressBar);
percentageTextView = findViewById(R.id.percentageTextView); // Show the
progress bar
horizontalProgressBar.setVisibility(ProgressBar.VISIBLE); // Set up a handler
to simulate an indeterminate animation with a percentage display final Handler
handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable()
{
int progress = 0;
@Override public void run() { // Update progress and percentage progress += 5;
horizontalProgressBar.setProgress(progress);
percentageTextView.setText(progress + "%"); // Repeat the animation if
(progress < 100)
{
handler.postDelayed(this, 500);
} else { // Hide the progress bar when the animation is complete
horizontalProgressBar.setVisibility(ProgressBar.GONE);
}
}
}, 500);
}
}

74
Output :-

75
Practical No 13:- Develop a program to implement Progress Bar

• .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" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="116dp"
android:text="download file" />
</RelativeLayout>

• MainActivity.java
package com.example.progressbar;
import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button btnStartProgress;
ProgressDialog progressBar;
private int progressBarStatus = 0;
private Handler progressBarHandler = new Handler();
private long fileSize = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButtonClick();
}

76
public void addListenerOnButtonClick() {
btnStartProgress = findViewById(R.id.button1);
btnStartProgress.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View v) {
// creating progress bar dialog
progressBar = new ProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("File downloading ...");

progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
progressBarStatus = 0;
fileSize = 0;

new Thread(new Runnable() {


public void run() {
while (progressBarStatus < 100) {
progressBarStatus = doOperation();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBarHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressBarStatus);}

});
}
if (progressBarStatus >= 100) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
progressBar.dismiss();
}
}
}).start();

77
}
});
}
public int doOperation() {
while (fileSize <= 10000) {
fileSize++;
if (fileSize == 1000) {
return 10;
} else if (fileSize == 2000) {
return 20;
} else if (fileSize == 3000) {
return 30;
} else if (fileSize == 4000) {
return 40;
}
}
return 100;
}
}

78
Output :

79
Practical No. 14: Develop a program to implement List View,
Grid View, Image View and Scroll View.

• Activity_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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textColor="#4d4d4d" />
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints"
android:layout_marginTop="30dp"/>
</LinearLayout>

• Strings.xml
<resources>
<string name="app_name">ListView</string>
<string-array name="array_technology">
<item>Android</item>
<item>Java</item>
<item>Php</item>
<item>Hadoop</item>

80
<item>Sap</item>
<item>Python</item>
<item>Ajax</item>
<item>C++</item>
<item>Ruby</item>
<item>Rails</item>
<item>.Net</item>
<item>Perl</item>
</string-array>
</resources>

• MainActivity.java
package com.example.listview;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
ListView listView;
TextView textView;
String[] listItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

listView=(ListView)findViewById(R.id.listView);
textView=(TextView)findViewById(R.id.textView);
listItem = getResources().getStringArray(R.array.array_technology);
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, listItem);
listView.setAdapter(adapter);

listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override

81
public void onItemClick(AdapterView<?> adapterView, View view,
int position, long l) {

String value=adapter.getItem(position);

Toast.makeText(getApplicationContext(),value,Toast.LENGTH_LONG).sho
w();

}
});
}
}

Output :

82
Practical No 15:- Develop a program to implement Custom Toast
Alert.

1. Write a program to display toast alert message

.java file

package com.example.practical_15;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@SuppressLint({"MissingInflatedId", "LocalSuppress"})
Button btn = (Button)findViewById(R.id.btnShow);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "You Clicked on Button..",
Toast.LENGTH_SHORT).show();
}
});
}
}

83
.xml file

<?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"
tools:context=".MainActivity"
>
<Button
android:id="@+id/btnShow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:text="Click to Show "
android:textColor="#FFF4F4"
android:padding="10dp"
android:textStyle="bold"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginLeft="80dp"
android:layout_marginRight="80dp"
android:layout_marginTop="125dp"
/>
</LinearLayout>

84
OUTPUT:-

85
Practical No 16 : Develop a program to implement Date and Time
Picker.

1. Develop a program to implement Date and Time Picker. TimePicker wit


Spinnermode.

.java file
package com.example.practical_15;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
TextView textview1;
TimePicker timepicker;
Button changetime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview1=(TextView)findViewById(R.id.textView1);
timepicker=(TimePicker)findViewById(R.id.timePicker);
//Uncomment the below line of code for 24 hour view
timepicker.setIs24HourView(true);
changetime=(Button)findViewById(R.id.button1);
textview1.setText(getCurrentTime());
changetime.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
textview1.setText(getCurrentTime());
}
});
}
public String getCurrentTime(){
String currentTime="Current Time:
"+timepicker.getCurrentHour()+":"+timepicker.getCurrentMinute();
return currentTime;
}
}

86
.xml file

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

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="102dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:text="" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:text="Change Time"
tools:ignore="TextSizeCheck" />

<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp" />

</RelativeLayout>

87
Output:

88
Practical No: 17 Develop a program to create an Activity.

1. Write a program to create a Hello World Activity using all lifecycles


methods to display message using Log.d.

java file

package com.example.practical_15;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Activity_Lifecycle","onCreate invoked");
Toast.makeText(MainActivity.this,"Created",Toast.LENGTH_SHORT).show();
}
@Override
protected void onStart() {
super.onStart();
Log.d("Activity_Lifecycle","onStart invoked");
Toast.makeText(MainActivity.this,"Start",Toast.LENGTH_SHORT).show();
}
@Override
protected void onResume() {
super.onResume();
Log.d("Activity_Lifecycle","onResume invoked");
Toast.makeText(MainActivity.this,"Resume",Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
super.onPause();
Log.d("Activity_Lifecycle","onPause invoked");
Toast.makeText(MainActivity.this,"Pause",Toast.LENGTH_SHORT).show();
}
@Override
protected void onStop() {
super.onStop();
Log.d("Activity_Lifecycle","onStop invoked");
Toast.makeText(MainActivity.this,"Stop",Toast.LENGTH_SHORT).show();
89
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("Activity_Lifecycle","onRestart invoked");
Toast.makeText(MainActivity.this,"Restart",Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("Activity_Lifecycle","onDestroy invoked");
Toast.makeText(MainActivity.this,"Destroy",Toast.LENGTH_SHORT).show();
}
}

.xml file

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_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:text="Activity Life Cycle"
android:textColor="#000000"
android:textSize="25dp"
android:gravity="center"
android:textStyle="bold"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>

</RelativeLayout>

90
OUTPUT :

91
Practical No: 18 Develop a program to implement new activity
using explicit intent and implicit intent.

1. Write a program to create a create text field and a button


“Navigate”. When you enter www.google.com and press navigate it
should open google page.

.java file

package com.example.practical_15;
import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private Button mSearchButton;
private EditText mEnterText;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSearchButton = (Button) findViewById(R.id.searchbutton);
mEnterText = (EditText) findViewById(R.id.enteredtext);
mSearchButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String etxt = mEnterText.getText().toString();
if(!etxt.isEmpty()) {
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY,etxt);
startActivity(intent);

92
}
else {
Toast.makeText(MainActivity.this,"Not entered
anything",Toast.LENGTH_LONG).show();
}
}
});
}
}

.xml file

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Search here"
android:id="@+id/enteredtext"
android:textColor="@color/black"
android:layout_marginTop="150dp"
android:layout_marginLeft="35dp"
android:layout_marginRight="35dp"
android:paddingLeft="20dp"
android:background="@drawable/shape"
/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"

93
android:id="@+id/searchbutton"
android:text="SEARCH"
android:layout_marginTop="30dp"
android:layout_below="@+id/enteredtext"
android:layout_gravity="center"
/>
</LinearLayout>

Output:

94
Practical No. 19: Develop a program to implement content provider

Activity_pr19.xml

<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=".practicalno19">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:orientation="vertical"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp">

<EditText
android:id="@+id/productNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Product Name"
android:inputType="textPersonName"
tools:ignore="Autofill" />

<EditText
android:id="@+id/productPriceEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ems="10"
android:hint="Enter Product Price"
android:inputType="numberDecimal"
tools:ignore="Autofill" />

95
<Button
android:id="@+id/addProductButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:textColor="@color/white"
android:textAlignment="center"
android:text="Add New Product" />

<Button
android:id="@+id/b1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show result"
android:layout_marginTop="15dp"/>

</LinearLayout>
</RelativeLayout>

Pr19.java

package com.ashish.practicals;
import android.content.ContentValues;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable; import


androidx.appcompat.app.AppCompatActivity;

public class practicalno19 extends AppCompatActivity { EditText


productNameEditText, productPriceEditText;

96
Button addProductButton,b1;

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

productNameEditText =
findViewById(R.id.productNameEditText);
productPriceEditText = findViewById(R.id.productPriceEditText);
addProductButton = findViewById(R.id.addProductButton);

b1 = findViewById(R.id.b1);

b1.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
Intent i = new
Intent(practicalno19.this,practicalno19_1.class);
startActivity(i);
}
});

addProductButton.setOnClickListener(view -> {
//get product name and price
String productName =
productNameEditText.getText().toString(); String
productPrice = productPriceEditText.getText().toString();

if (!productName.isEmpty() && !productPrice.isEmpty()) {


//Key-value object to add value in the database
ContentValues values =new ContentValues();
values.put(Content_Provider.name, productName);
values.put(Content_Provider.price, productPrice);

//insert data using Content URI

97
Uri uri =
getContentResolver().insert(Content_Provider.CONTENT_URI,
values);
Toast.makeText(this, uri.toString(),
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Please fill all fields",
Toast.LENGTH_SHORT).show();
}
});
}
}

OUTPUT :-

98
Practical No. 20: Develop a program to implement service

MyService.java
package com.spworld.practicals;
import android.app.Service;
import android.content.Intent; import android.media.MediaPlaye;
import android.os.IBinder;
import android.widget.Toast;

public class MyService extends Service {


MediaPlayer myPlayer;

@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
Toast.makeText(this, "Service Created",
Toast.LENGTH_LONG).show();
myPlayer = MediaPlayer.create(this, R.raw.faded);
myPlayer.setLooping(false);
}

99
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "Service
Started",Toast.LENGTH_LONG).show();
myPlayer.start();
}

@Override
public void onDestroy() {
Toast.makeText(this, "Service Stopped",
Toast.LENGTH_LONG).show();
myPlayer.stop();
}
}

100
Practicalno20.java

package com.ashish.practicals;
import androidx.appcompat.app.AppCompatActivit; import
android.content.Intent;
import android.os.Bundle; import android.view.View; import
android.widget.Button;
public class practicalno20 extends AppCompatActivity {
Button buttonStart, buttonStop,buttonNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_practicalno20);
buttonStart = findViewById(R.id.buttonStart);
buttonStop = findViewById(R.id.buttonStop);
buttonNext = findViewById(R.id.buttonNext);
buttonStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startService(new Intent(practicalno20.this, MyService.class));
}
});
buttonStop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stopService(new Intent(practicalno20.this, MyService.class));

101
}
});
buttonNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new
Intent(practicalno20.this,practicalno20_1.class);
startActivity(intent);
}
});
}
}

102
activity_practicalno20.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=".practicalno20">

<Button
android:id="@+id/buttonStart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="Start Service" />

<Button
android:id="@+id/buttonStop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/buttonStart"
android:text="Stop Service" />

103
<Button
android:id="@+id/buttonNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="100dp"
android:text="Next Page" />

</RelativeLayout>

104
OUTPUT :-

105
Practical No: 21 Develop a program to implement broadcast
receiver
AndroidManifest.xml file
<?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.RECEIVE_BOOT_COMPLETE
D" />
<uses-permission
android:name="android.permission.ACTION_POWER_CONNECTE
D" />
<uses-permission
android:name="android.permission.ACTION_POWER_DISCONNE
CTED"/>
<uses-permission
android:name="android.permission.BATTERY_CHANGED" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="Practical_21"
android:supportsRtl="true"
android:theme="@style/Theme.Practical_15"
tools:targetApi="31">

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

.java file
package com.example.practical_15;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {

107
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textview);
// Register broadcast receivers for various system broadcasts
registerReceiver(new BootReceiver(), new
IntentFilter(Intent.ACTION_BOOT_COMPLETED));
registerReceiver(new PowerConnectedReceiver(), new
IntentFilter(Intent.ACTION_POWER_CONNECTED));
registerReceiver(new PowerDisconnectedReceiver(), new
IntentFilter(Intent.ACTION_POWER_DISCONNECTED));
registerReceiver(new BatteryChangedReceiver(), new
IntentFilter(Intent.ACTION_BATTERY_CHANGED));}
private class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String message = "System boot completed";
textView.setText(message);}
}
private class PowerConnectedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String message = "Power connected";
textView.setText(message);}
}

108
private class PowerDisconnectedReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent) {
String message = "Power disconnected";
textView.setText(message);}
}
private class BatteryChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
String message = "Battery level: " + level;
textView.setText(message);}
}
}

109
.xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:textStyle="bold"
android:layout_centerInParent="true"
android:textColor="#B02DC6"
/>
</RelativeLayout>

110
Output:

111
Practical No: 22 Develop a program to implement sensors.

AndroidManifest.xml file
<?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.RECEIVE_BOOT_COMPLETE
D" />
<uses-permission
android:name="android.permission.ACTION_POWER_CONNECTE
D" />
<uses-permission
android:name="android.permission.ACTION_POWER_DISCONNE
CTED" />
<uses-permission
android:name="android.permission.BATTERY_CHANGED" />
<uses-permission
android:name="android.permission.ACTION_SHUTDOWN" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="Practical_21"
android:supportsRtl="true"

112
android:theme="@style/Theme.Practical_15"
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>

.java file
package com.example.practical_15;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

113
public class MainActivity extends AppCompatActivity {
private LinearLayout mainLayout;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainLayout = (LinearLayout) findViewById(R.id.main_layout);
textView = (TextView) findViewById(R.id.textview);
registerReceiver(shutdownReceiver,
new IntentFilter(Intent.ACTION_SHUTDOWN));
}
private BroadcastReceiver shutdownReceiver = new
BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Device shuffled!",
Toast.LENGTH_LONG).show();
mainLayout.setBackgroundColor(Color.rgb(255, 0, 0));
textView.setText("Device shuffled! Background
color changed.");
}
};
}

114
.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_marginLeft="15dp"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:textColor="#171717"
android:layout_marginRight="15dp"
android:text="Shuffle your device
to change the background color"
/>
</LinearLayout>

115
Output:

116
AndroidManifest.xml file
<?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.ACCESS_NETWORK_STATE"
/>
<uses-permission android:name="android.permission.INTERNET"
/>
<uses-permission
android:name="android.permission.ACCESS_WIFI_STATE" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="Practical_22"
android:supportsRtl="true"
android:theme="@style/Theme.Practical_15"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:label="Sensor List"
android:exported="true">
<intent-filter>

117
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
.java file
package com.example.practical_15;
import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private SensorManager sensorManager;
private TextView sensorListTextView;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sensorManager = (SensorManager)

118
getSystemService(Context.SENSOR_SERVICE);
sensorListTextView = findViewById(R.id.sensor_list_textview);
List<Sensor> sensorList =
sensorManager.getSensorList(Sensor.TYPE_ALL);
StringBuilder sensorListStringBuilder = new StringBuilder();
for (Sensor sensor : sensorList) {
sensorListStringBuilder.append(sensor.getName()).append("\n");}
sensorListTextView.setText(sensorListStringBuilder.toString());
.xml file
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView
android:id="@+id/sensor_list_textview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/black"
android:textSize="23dp"
android:textStyle="bold"
/>
</RelativeLayout>

119
OUTPUT:-

120
Practical No: 23 Develop a program to build Camera

AndroidManifest.xml file
<?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" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="Practical_23"
android:supportsRtl="true"
android:theme="@style/Theme.Practical_15"
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>

121
</application>
</manifest>

.java file
package com.example.practical_15;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
public class MainActivity extends AppCompatActivity {
Button button; ImageView imageView; Intent intent;
public static final int RequestPermissionCode = 1 ;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

122
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
imageView = (ImageView)findViewById(R.id.imageView);
EnableRuntimePermission();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
intent = new Intent(android.provider.
MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 7);
}});}
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 7 && resultCode == RESULT_OK) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}}
public void EnableRuntimePermission(){
if (ActivityCompat.shouldShowRequestPermissionRationale
(MainActivity.this,
Manifest.permission.CAMERA))
{
Toast.makeText(MainActivity.this,
"CAMERA permission allows us to Access CAMERA app",

123
Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{
Manifest.permission.CAMERA}, RequestPermissionCode);
}}
@Override
public void onRequestPermissionsResult(int RC, String per[],
int[] PResult) {
super.onRequestPermissionsResult(RC, per, PResult);
switch (RC) {
case RequestPermissionCode:
if (PResult.length > 0 && PResult[0] ==
PackageManager.PERMISSION_GRANTED) {
Toast.makeText(MainActivity.this,
"Permission Granted, Now your application can access CAMERA.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MainActivity.this,
"Permission Canceled, Now your application cannot access
CAMERA."
, Toast.LENGTH_LONG).show();
} break;}
}
}

124
.xml file
<?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/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#FFFFFF">
<ImageView
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:id="@+id/imageView" />
<Button
android:text="Click here to capture image using camera"
android:layout_width="match_parent"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:layout_height="wrap_content"
android:id="@+id/button" />
</LinearLayout>

125
OUPUT :-

126
Practical No: 24 Develop a program for providing Bluetooth
connectivity.

AndroidManifest.xml file
<?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.BLUETOOTH_ADVERTISE" />
<uses-permission
android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission
android:name="android.permission.BLUETOOTH" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="Practical_23"
android:supportsRtl="true"
android:theme="@style/Theme.Practical_15"
tools:targetApi="31">

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

.java file
package com.example.practical_15;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.core.app.ActivityCompat;

128
public class MainActivity extends Activity {
private static final int REQUEST_ENABLE_BT = 0;
private static final int REQUEST_DISCOVERABLE_BT = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView out = (TextView) findViewById(R.id.out);
final Button button1 = (Button) findViewById(R.id.button1);
final Button button2 = (Button) findViewById(R.id.button2);
final Button button3 = (Button) findViewById(R.id.button3);
final BluetoothAdapter mBluetoothAdapter =
BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
out.append("device not supported");
}
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
if (ActivityCompat.checkSelfPermission
(MainActivity.this,
android.Manifest.permission.BLUETOOTH_CONNECT)
!= PackageManager.PERMISSION_GRANTED) {

129
return;
}startActivityForResult(enableBtIntent,
REQUEST_ENABLE_BT);
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (ActivityCompat.checkSelfPermission( MainActivity.this,
android.Manifest.permission.BLUETOOTH_SCAN)
!= PackageManager.PERMISSION_GRANTED) {
return;
}
if (!mBluetoothAdapter.isDiscovering()) {
//out.append("MAKING YOUR DEVICE DISCOVERABLE");
Toast.makeText(getApplicationContext(),
"MAKING YOUR DEVICE DISCOVERABLE",
Toast.LENGTH_LONG);
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(enableBtIntent,
REQUEST_DISCOVERABLE_BT);
}
}

130
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (ActivityCompat.checkSelfPermission(MainActivity.this,
android.Manifest.permission.BLUETOOTH_CONNECT)
!= PackageManager.PERMISSION_GRANTED) {
return;
}
mBluetoothAdapter.disable();
//out.append("TURN_OFF BLUETOOTH");
Toast.makeText(getApplicationContext(),
"TURNING_OFF BLUETOOTH", Toast.LENGTH_LONG);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}

131
.xml file
<?xml version="1.0" encoding="UTF-8" ?>
<LinearLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:text=" "
android:id="@+id/out"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="@+id/button1"
android:layout_alignLeft="@+id/button1"
android:layout_marginLeft="130dp"
android:layout_marginTop="50dp"

132
android:text="DISCOVERABLE" />
<Button
android:id="@+id/button1"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="130dp"
android:layout_marginTop="50dp"
android:text="TURN_ON" />
<Button
android:id="@+id/button3"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginLeft="130dp"
android:layout_marginTop="50dp"
android:text="TURN_OFF" />
</LinearLayout>

133
OUTPUT :-

134
Practical No: 25 Develop a program for animation.

.java file
package com.example.practical_15;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void rotate(View view) {
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation = AnimationUtils.loadAnimation
(getApplicationContext(),
R.anim.rotate);
image.startAnimation(animation);
}
public void anti(View view) {
ImageView image = (ImageView)findViewById(R.id.imageView);

135
Animation animation = AnimationUtils.loadAnimation
(getApplicationContext(),
R.anim.anti);
image.startAnimation(animation);
}
public void zoom_in(View view) {
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation = AnimationUtils.loadAnimation
(getApplicationContext(),
R.anim.zoom_in);
image.startAnimation(animation);
}
public void zoom_out(View view) {
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation = AnimationUtils.loadAnimation
(getApplicationContext(),
R.anim.zoom_out);
image.startAnimation(animation);
}
}

136
.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/image"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clockwise"
android:id="@+id/button"
android:layout_marginTop="0dp"
android:gravity="center"
android:layout_gravity="center"
android:onClick="rotate"/>

137
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anticlockwise"
android:id="@+id/button2"
android:layout_marginTop="10dp"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:onClick="anti"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom in"
android:id="@+id/button4"
android:gravity="center"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:onClick="zoom_in"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom out"
android:id="@+id/button3"

138
android:gravity="center"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="8dp"
android:onClick="zoom_out"/>
</LinearLayout>

Zoom_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="2"
android:fromYScale="2"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="4"
android:toYScale="4" >
</scale>
</set>

139
Zoom_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="2500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale=".2"
android:toYScale=".2" />
</set>
Clockwise.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/cycle_interpolator">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000" />
</set>

140
Anticlockwise.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/cycle_interpolator">
<rotate
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000" />
</set>

141
Output:-

142
143

You might also like