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

Android programming

This document is a practical file submitted by Jatin Aggarwal for the Android Programming Laboratory course at Gian Jyoti Institute of Management and Technology. It includes a table of contents outlining various practical exercises related to Java and Android development, such as installation of Java and Android Framework, usage of Android SDK components, and programming examples. The document serves as a guide for completing the practical requirements for the Bachelor of Computer Application degree.

Uploaded by

rgautamrai28
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)
5 views

Android programming

This document is a practical file submitted by Jatin Aggarwal for the Android Programming Laboratory course at Gian Jyoti Institute of Management and Technology. It includes a table of contents outlining various practical exercises related to Java and Android development, such as installation of Java and Android Framework, usage of Android SDK components, and programming examples. The document serves as a guide for completing the practical requirements for the Bachelor of Computer Application degree.

Uploaded by

rgautamrai28
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/ 53

PRACTICAL FILE

Submission, Session: (Jan–June, 2025)

GIAN JYOTI INSTITUTE OF MANAGEMENT


&
TECHNOLOGY
SAS Nagar, Phase-II, Mohali
Affiliated to

PUNJAB TECHNICAL UNIVERSITY, JALANDHAR


In the partial fulfillment of the requirement for the award of the degree of
Bachelors of Computer Application

SUBMITTED TO: SUBMITTED BY:


Mrs. Jaspreet Kaur Name: Jatin Aggarwal
Course: Android Programming Laboratory University Roll No:2211600
Course Code: UGCA1944 Class: BCA- VI (A)
Department of COMPUTER APPLICATIONS
TABLE OF CONTENT

Sr Name of Practical Page no. Signature


no.
1 Installation of Java, android Framework 1-11

2 Android SDK Manager and its all components 12-16

3 Programs based on the overriding, constructor, 17-18


classes in Java
4 Programs based on the Final, this and static 19-20
keyword in Java
5 Directory Structure of an Android Project, 21-23
Common Default Resources Folders, The Values
Folder, Leveraging Android XML.
6 Applications based on Text Boxes and Button 24-25

7 Applications based on Check Boxes and button 26-27

8 Applications based on Radio Buttons 28-30

9 Applications based on Intents and Intent Filters 31-32

10 Applications based on Activities and services 33-35

11 Applications based on Action Bar 36

12 Applications based on Option Menu 37-38

13 Applications based on Rating Bar 39-40

14 Applications based on Media Player 41-42


15 Applications based on Content Providers 43-45

16 Applications based on accessing camera 46

17 Applications based on accessing location 47-48

18 Applications based on the activation of sensors 49

19 Applications based on Animations 50

Date: Signature:
Practical No. 1: - Installation of Java, android Framework
Installation of Java: -
Step 1: Verify that it is already installed or not
Check whether Java is already installed on the system or not. In my case, it is not
installed therefore I need to install JDK 1.8 on my computer.

Step 2: Download JDK


Click the link below to download jdk 1.8 for your windows 64 bit system.
Download JDK For Windows
There are available releases for Linux and mac operating systems.
Step 3: Install JDK
Open the executable file which you have just downloaded and follow the steps.

Click Next to continue

1
Just Choose Development Tools and click Next.

Set up is ready

2
Choose the Destination folder in which you want to install JDK. Click Next to
continue with the installation.

Setup is installing Java to the computer.

We have successfully installed Java SE development kit 8. Close the installation


setup.
Step 4 : Set the Permanent Path
To execute Java applications from the command line, we need to set Java Path. To
set the path, follow the following steps.

3
Right click on "this PC". It can be named as "My Computer" in some systems.
Choose "properties" from the options.

4
The screen looks like the above image will open. Click on "Advanced system
settings" to continue

The window will open. Click on "Environment Variables" to continue.

Enter "path" in variable name and enter the path to the bin folder inside your JDK
in the variable value. Click OK.
Now Java Path has been set up. Open the Command prompt and type "javac" In
case you have already opened up the command prompt, I suggest you close the
existing window and reopen it again.
5
We will get javac executed as shown in the image below.

Java has been installed on our system.

Installation of Android Framework : -

Step 1: Head over to this link to get the Android Studio executable or zip file.
Step 2: Click on the Download Android Studio Button.

6
Click on the “I have read and agree with the above terms and conditions”
checkbox followed by the download button.

Click on the Save file button in the appeared prompt box and the file will start
downloading.
Step 3: After the downloading has finished, open the file from downloads and run
it. It will prompt the following dialog box.

7
Click on next. In the next prompt, it’ll ask for a path for installation. Choose a path
and hit next.
Step 4: It will start the installation, and once it is completed, it will be like the
image shown below.

Click on next.

Step 5: Once “Finish” is clicked, it will ask whether the previous settings need to
be imported [if the android studio had been installed earlier], or not. It is better to
choose the ‘Don’t import Settings option’ .

8
Click the OK button.
Step 6: This will start the Android Studio.

Meanwhile, it will be finding the available SDK components.

Step 7: After it has found the SDK components, it will redirect to the Welcome
dialog box.

Click on Next.

9
Choose Standard and click on Next. Now choose the theme, whether the Light
theme or the Dark one. The light one is called the IntelliJ theme whereas the dark
theme is called Dracula. Choose as required.

Click on the Next button.


Step 8: Now it is time to download the SDK components.

10
Click on Finish. Components begin to download and let it complete.

The Android Studio has been successfully configured. Now it’s time to launch and
build apps. Click on the Finish button to launch it.
Step 9: Click on Start a new Android Studio project to build a new app.

11
Practical No. 2: - Android SDK Manager and its all components.
About Android SDK:
Android SDK is a collection of libraries and Software Development tools that are
essential for Developing Android Applications. Whenever Google releases a new
version or update of Android Software, a corresponding SDK also releases with it.
In the updated or new version of SDK, some more features are included which are
not present in the previous version. Android SDK consists of some tools which are
very essential for the development of Android Application. These tools provide a
smooth flow of the development process from developing and debugging.
Android SDK is compatible with all operating systems such as Windows, Linux,
macOS, etc.

Components of Android SDK


Android SDK Components play a major role in the Development of Android
applications. Below are the important components:
1. Android SDK Tools
Android SDK tool is an important component of Android SDK. It consists of a
complete set of development and debugging tools. Below are the SDK developer
tools:

12
• Android SDK Build tool.
• Android Emulator.
• Android SDK Platform-tools.
• Android SDK Tools.
These are shown below :

2. Android SDK Build-Tools


Android SDK build tools are used for building actual binaries of Android Apps. The
main functions of Android SDK Build tools are built, debug, run and test Android
applications. The latest version of the Android SDK

Build tool is 30.0.3. While downloading or updating Android in our System, one
must ensure that its latest version is downloaded in SDK Components.
3. Android Emulator
An Android Emulator is a device that simulates an Android device on your system.
Suppose we want to run our android application that we code. One option is that
we will run this on our Android Mobile by Enabling USB Debugging on our mobile.
13
Another option is using Android Emulator. In Android Emulator the virtual android
device is shown on our system on which we run the Android application that we
code.
Thus, it simply means that without needing any physical device Android SDK
component “Android Emulator” provides a virtual device on the System where we
run our Application. The emulator’s come with the configuration for Various
android phones, tablets, Wear OS, and Android TV devices.

In Android Virtual Emulator all functions that are feasible on real Android mobile
is works on virtual Device like:
• phone calls, text messages.
• simulate different network speeds.
• specify the location of a device
• access on google play store and lot’s more.

14
But there is one disadvantage of this emulator. It is very slow when System’s PC
has less RAM. It works fine when a maximum GB of RAM is present on our device.
4. Android SDK Platform-tools
Android SDK Platform-tools is helpful when we are working on a Project and they
will show the error messages at the same time. It is specifically used for testing. It
includes:
• Android Debug Bridge (ADB), is a command-line tool that helps to
communicate with the device. It allows us to perform actions such as Installing
apps, Debugging apps, etc.
• Fastboot allows you to flash a device with a new system image.
• Systrace tools help to collect and inspect timing information. It is very
crucial for App Debugging.
5. Android SDK Tools
Android SDK tool is a component of SDK tool. It consists of a set of tools and other
Utilities which are crucial for the development of Android Application. It contains
the complete set of Debugging and Development tools for android.
6. SDK Platforms
For Each Android Software, one SDK platform is available as shown below:

Like in this Android 11.0(R) is installed.

15
These are numbered according to the android version. The new version of the
SDK platform has more features and is more compatible but the old version is less
compatible with fewer features. Like in Android 11.0(R) are more compatible and
have more features but the below versions like Android 10.0(Q),
Android4.4(KitKat) have less features and are less compatible.
7. SDK Update Sites
In SDK Update Sites, some sites are embedded in it which will check for Android
SDK Updates Tools. In this, one must ensure we don’t unclick the button below
because these are checked by default which will check for updates if we will
unclick it then it doesn’t check updates for those.

16
Practical No. 3 : - Programs based on the overriding, constructor,
classes in Java Method Overriding in Java
//Java Program to illustrate the use of Java Method Overriding
//Creating a parent class.
Class Vehicle{
//defining a method
Void run(){System.out.println("Vehicle is running");}
}
//Creating a child class
class Bike2 extends Vehicle{
//defining the same method as in the parent class
void run(){System.out.println("Bike is running safely");}
public static void main(String args[]){
Bike2 obj = new Bike2();//creating object
obj.run();//calling method
}
}
Output:

default constructor
//Java Program to create and call a default constructor
class Bike1{
//creating a default constructor
Bike1(){System.out.println("Bike is created");}
//main method
public static void main(String args[]){
//calling a default constructor
Bike1 b=new Bike1();
}

17
}
Output:

18
Practical No. 4: - Programs based on the Final, this and static keyword
in Java
Final Keyword In Java
class Bike9{
final int speedlimit=90;//final variable
void run(){
speed limit=400;
}
public static void main(String args[]){
Bike9 obj=new Bike9();
obj.run();
}
}
//end of class
Output:

Java static keyword


//Java Program to get the cube of a given number using the static method
class Calculate{
static int cube(int x){
return x*x*x;
}
public static void main(String args[]){
int result=Calculate.cube(5);
System.out.println(result);
}
}
Output: -

19
this keyword in Java
class A{
void m(){System.out.println("hello m");}
void n(){
System.out.println("hello n");
//m();//same as this.m()
this.m();
}
}
class TestThis4{
public static void main(String args[]){
A a=new A();
a.n();
}}

Output: -

20
Practical No. 5: - Directory Structure of an Android Project, Common
Default Resources Folders, The Values Folder, Leveraging Android
XML.
Android Project folder Structure: Android Studio is the official IDE (Integrated
Development Environment) developed by the Jet Brains community which is
freely provided by Google for android app development. After completing the
setup of Android Architecture we can create an android application in the studio.
We need to create a new project for each sample application and we should
understand the folder structure. It looks like this:

The android project contains different types of app modules, source code files,
and resource files. We will explore all the folders and files in the android app.
1. Manifests Folder
2. Java Folder
3. res (Resources) Folder
• Drawable Folder
• Layout Folder
• Mipmap Folder
• Values Folder
4. Gradle Scripts
Manifests Folder
Manifest folder contains AndroidManifest.xml for creating our android
application. This file contains information about our application such as the
Android version, metadata, states package for Kotlin file, and other application

21
components. It acts as an intermediary between android OS and our application.
Following is the manifest folder structure in the android application.

Java folder
The Java folder contains all the java and Kotlin source code (.java) files that we
create during the app development, including other Test files. If we create any
new project using Kotlin, by default the class file MainActivity.kt file will create
automatically under the package name “com.geeksforgeeks.myfirstkotlinapp” as
shown below.

Resource (res) folder


The resource folder is the most important folder because it contains all the non-
code sources like images, XML layouts, and UI strings for our android application.

22
res/drawable folder
It contains the different types of images used for the development of the
application. We need to add all the images in a drawable folder for the application
development.
res/layout folder
The layout folder contains all XML layout files which we used to define the user
interface of our application. It contains the activity_main.xml file.
res/mipmap folder
This folder contains launcher.xml files to define icons that are used to show on
the home screen. It contains different density types of icons depending upon the
size of the device such as hdpi, mdpi, xhdpi.
res/values folder
The Values folder contains a number of XML files like strings, dimensions, colors,
and style definitions. One of the most important files is the strings.xml file which
contains the resources.
Gradle Scripts folder
Gradle means automated build system and it contains a number of files that are
used to define a build configuration that can be applied to all modules in our
application. In build.gradle (Project) there are build scripts and in build.gradle
(Module) plugins and implementations are used to build configurations that can
be applied to all our application module

23
Practical No. 6: - Applications based on Text Boxes and Button
<?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="example.javatpoint.com.sumoftwonumber.MainActivity">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
droid:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="61dp"
android:ems="10"
android:inputType="number"
tools:layout_editor_absoluteX="84dp"
tools:layout_editor_absoluteY="53dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:ems="10"
android:inputType="number"
tools:layout_editor_absoluteX="84dp"
tools:layout_editor_absoluteY="127dp" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:text="ADD"
24
tools:layout_editor_absoluteX="148dp"
tools:layout_editor_absoluteY="266dp" />
</RelativeLayout>

Output: -

25
Practical No7: - Applications based on Checkboxes and button.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns:android="http://schemas.an
droid.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="example.javatpoint.com.checkbox.MainActivity">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="68dp"
android:text="Pizza"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:text="Coffee"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:text="Burger"
26
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox2" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="184dp"
android:text="Order"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox3" />
</android.support.constraint.ConstraintLayout>

Output: -.

27
Practical No8: - Applications based on Radio Buttons
<?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"
android:orientation="vertical"
tools:context="example.javatpoint.com.radiobutton.MainActivity">
<TextView android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:textSize="22dp"
android:text="Single Radio Buttons" />
<!-- Default RadioButtons -->
<RadioButton android:id="@+id/radioButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Radio Button 1"
android:layout_marginTop="20dp"
android:textSize="20dp" />
<RadioButton android:id="@+id/radioButton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Radio Button 2"
android:layout_marginTop="10dp"
android:textSize="20dp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="20dp"
android:background="#B8B894" />
<TextView
android:id="@+id/textView2"
28
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:textSize="22dp"
android:text="Radio button inside RadioGroup" />
<!-- Customized RadioButtons -->
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup">
<RadioButton
android:id="@+id/radioMale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Male"
android:layout_marginTop="10dp"
android:checked="false"
android:textSize="20dp" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Female"
android:layout_marginTop="20dp"
android:checked="false" android:textSize="20dp" />
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:id="@+id/button"
android:onClick="onclickbuttonMethod"
android:layout_gravity="center_horizontal" />
</LinearLayout>

29
Output: -

30
Practical No9: - Applications based on Intents and Intent Filters.

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

<android.support.constraint.ConstraintLayoutxmlns:android="http://schem
as.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="example.javatpoint.com.implicitintent.MainActivity">

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:ems="10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.575"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginLeft="156dp"
android:layout_marginTop="172dp"
android:text="Visit"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />

31
</android.support.constraint.ConstraintLayout>

Output: -

32
Practical No10: - Applications based on Activities and services
<?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="example.javatpoint.com.androidservice.MainActivity">
<Button
android:id="@+id/buttonStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="74dp"
android:text="Start Service" />
<Button
android:id="@+id/buttonStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Stop Service" />
<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="63dp"
android:text="Next Page" />
</RelativeLayout>
activity_next.xml
<?xml version="1.0" encoding="utf-8"?>

33
<android.support.constraint.ConstraintLayout
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="example.javatpoint.com.androidservice.NextPage">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="200dp"
android:text="Next Page"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

File: AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=http://schemas.android.com/apk/res/android
package="example.javatpoint.com.androidservice">
<application android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".NextPage"></activity>

34
<service android:name=".MyService"
android:enabled="true" />
</application>
</manifest>

Output: -

35
Practical No 11: - Applications based on Action Bar
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app=http://schemas.android.com/apk/res-auto
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- action button for search -->
<item android:title="search"
android:id="@+id/search"
android:orderInCategory="100"
app:showAsAction="ifRoom"
android:icon="@drawable/search_icon"/>
<!-- action button for refresh -->
<item android:title="refresh"
android:id="@+id/refresh"
android:orderInCategory="100"
app:showAsAction="ifRoom"
android:icon="@drawable/refresh_icon"/>
<!-- action button for copy -->
<item android:title="copy"
android:id="@+id/copy"
android:orderInCategory="100" app:showAsAction="never"
android:icon="@drawable/copy_icon"/>
</menu>

Output: -

36
Practical No 12: - Applications based on Option Menu File:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/and roid"
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="example.javatpoint.com.optionmenu.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
File: context_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="example.javatpoint.com.optionmenu.MainActivity"
tools:showIn="@layout/activity_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
37
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
File: menu_main.xml
<menu
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"
tools:context="example.javatpoint.com.optionmenu.MainActivity">
<item android:id="@+id/item1" android:title="Item 1"/>
<item android:id="@+id/item2" android:title="Item 2"/>
<item android:id="@+id/item3" android:title="Item 3"
app:showAsAction="withText"/>
</menu>
Output:

38
Practical No.13: - Applications based on Rating Bar
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns:android="http://schem
as.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="example.javatpoint.com.ratingbar.MainActivity">

<Button

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit" android:id="@+id/button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.615" />

<RatingBar android:id="@+id/ratingBar"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="72dp"
android:layout_marginTop="60dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

39
Output: -

40
Practical No 14 : - Applications based on Media Player
<RelativeLayout
xmlns:androclass="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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp"
android:text="Audio Controller" />
<Button
android:id="@+id/button1" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="48dp"
android:text="start" />
<Button
android:id="@+id/button2" style="?
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button1"
android:layout_toRightOf="@+id/button1"
android:text="pause" />
<Button
android:id="@+id/button3" style="?
41
android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button2"
android:layout_toRightOf="@+id/button2"
android:text="stop" />
</RelativeLayout>

Output: -

42
Practical No 15: - Applications based on Content Providers
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:background="#168BC34A"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@+id/imageView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.13"
tools:ignore="MissingConstraints">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"

android:layout_marginBottom="70dp"
android:fontFamily="@font/roboto"
android:text="@string/heading"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/holo_green_dark"
android:textSize="36sp"
android:textStyle="bold" />
<Button
43
android:id="@+id/loadButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#4CAF50"
android:fontFamily="@font/roboto"
android:onClick="onClickShowDetails"
android:text="@string/loadButtonText"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="@+id/res"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:clickable="false" android:ems="10"
android:fontFamily="@font/roboto"
android:textColor="@android:color/holo_green_dark"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/banner" />
</androidx.constraintlayout.widget.ConstraintLayout>

44
Output: -

45
Practical No 16: - Applications based on accessing camera
<RelativeLayout xmlns:androclass=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" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Take a Photo" >
</Button>
<ImageView android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button1"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" >
</ImageView>
</RelativeLayout>
Output: -

46
Practical No 17: - Applications based on accessing location
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.com.mapexample">
<!--The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine location
permissions for the 'MyLocation' functionality.-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--The API key for Google Maps-based APIs is defined as a string resource. (See
the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key
that is used to sign the APK for publishing.You can define the keys for the debug
and release targets in src/debug/ and src/release/.-->
<meta-data android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

47
</manifest>

Output: -

48
Practical No 18: Applications based on the activation of sensors

<RelativeLayout
xmlns:androclass="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/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="92dp" android:layout_marginTop="114dp"
android:text="TextView" />
</RelativeLayout>

Output: -

49
Practical No 19: - Applications based on Animations
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<View/>
</RelativeLayout>
File: logo.xml
Have an image view only.
<?xml version="1.0" encoding="utf-8"?>
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/anm">

</ImageView>

Output: -

50

You might also like