0% found this document useful (0 votes)
24 views71 pages

Lab Manual MAD CS3163

Uploaded by

Vighu Patil
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)
24 views71 pages

Lab Manual MAD CS3163

Uploaded by

Vighu Patil
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/ 71

LAB MANUAL

Course: Mobile Application Development Lab


Course Code: CS3163
Class: - TY B. Tech Semester: VI

Course Learning Outcomes(CO):


After successful completion of the course, students will be able to:
1. Setup the Android development environment
2. Utilize the appropriate User Interface controls in Android app
3. Implement SQLite and Shared Preferences concepts to store data in Androidapp
4. Implement Location and Notification based functionalities in Android app
5. Design and develop a WebView based Android app
6. Build and deploy Android app on Google Play Store
Experiment List

Experiment
Title of experiment Course outcomes covered
No
1 Environment Setup( Installation of java and CO1
Android Studio)
2 Implement Linear Layout and Relative
CO2
Layout .
3 Implement Table Layout, Absolute Layout CO2
and Frame Layout
4 Create User interface for signup activity using CO2
required layout and views.
5 Implement concept of Event Handling. CO2
6 Develop a program to implement new activity
CO2
using explicit intent and implicit intent.
7 Develop application for storing data
CO3
with SQLite and SharedPreferences
8 Implement Location and Notification based CO4
functionalities
9 Implement the concept of webview. CO5
10 Understand Play store Deployment Process CO6
Experiment No 1

Title:Environment Setup ( Installation of java and Android Studio)

Practical Significance:

Android is based on Linux with a set of native core C/C++ libraries. Android applications are
written in Java. However, they run on Android's own Java Virtual Machine, called Dalvik
Virtual Machine (DVM) (instead of JDK's JVM) which is optimized to operate on the small and
mobile devices. SDK provides a selection of tools required to build Android apps or to ensure
the process goes as smoothly as possible. Whether creating an app with Java, Kotlin or C#, SDK
should run on an Android device and access unique features of the OS.

Relevant Course Outcomes(What you will learn?)

CO 1: Configure Android environment and development tools

What you will need?

 Operating System Version - Microsoft Windows 7/8/10 (32-bit or 64-


bit)/Linux,macOS(10.14 Mojaver or later) or Chrome OS.
 Random Access Memory (RAM) - Minimum 4 GB RAM and 8 GB RAM recommended.
 Free Disk Space - Minimum 2 GB and 4 GB recommended.
 Minimum Required JDK Version - Java Development Kit (JDK) 8.
 Minimum Screen Resolution - 1280 * 800.resolution

Step No 1: download and configure JDK


Student’s should know how to 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.

Step No 2:Download the Android Studios latest version from the official Android Studio
website in your web browser. https://developer.android.com/studio/
Step No3:Double click on the downloaded "Android Studio-ide.exe" file

Step 4: Run Android studio setup file by double clicking on downloaded file, follow instructions
given and complete the setup.
Step 5 Creating new Project :Click FileNew->New Project
In the new project window select empty activity and click next

Then following new project window will open


Fill required details and click on finish button.

To execute your application you must have to create AVD (Android Virtual Device) or you can
use your personal physical smart android phone

Step No 6 :Creating Android application in AVD

You can run android application using two methods

1. AVD(Android Virtual Device)

What is AVD ?

Using AVD you can test your app on different size of devices and on different versions of
Android OS .In market there are mobile devices with different OS, so AVD is useful to test app
on different versions of Android.

2. ADB (Android Debug Brig) or

Using ADB we can run app on real physical device(On Mobile phone)

Creating Android Virtual Device

First click on Device manager on toolbar or in the menu

Click on virtual tab and then on create device

Select category of device you want and select device size

Select system image for your phone(Select latest version id not available click on download,
internet must be on)

Give name to AVD

Select orientation portrait or landscape

Click on finish

Now your device is visible in the Device Manager in the virtual tab

Step NO 7:Select your device in tool bar and run your app
Conclusion: Before starting android application development proper environment setup is
required it involves downloading and configuring JDK and downloading and configuring
Android Studio and creating AVD for executing your application

Experiment No 2
Title: Implement Linear Layout and Relative Layout .
Practical Significance:

To develop and place the android views accurately on the display screen, android provides various
layouts. Various layouts can be used as per the program requirements.

Relevant Course Outcomes(What you will learn?)

CO 2: . Utilize the appropriate User Interface controls in Android app

Minimum Theoretical Background

Layouts which are subclasses of View Group class and a typical layout defines the visual
structure for an Android user interface .You can create your layout in activity_main.xml which is
located in the res/layout folder of your project. layouts defined in XML file. A layout may
contain any type of widgets such as buttons, labels, textboxes etc. Layout Attributes Each layout
has a set of attributes which define the visual properties of that layout. There are few common
attributes among all the layouts and there are other attributes which are specific to that layout.

Linear Layout

By using Linear Layout you can arrange views either vertically or horizontally as shown in
following diagram.
Figure 1 :Android Linear Layout

Important attribute of linear layout

It is defined individually to the child’s views to specify


how LinearLayout
android:layout_weight
divides the remaining space amongst the views it
contains

How the elements should be arranged in the layout. It


android:orientation
can be horizontal or vertical.

It specifies how an object should position its content on


its X and Y axes.
android:gravity
Possible values are – center_vertical, fill, center,
bottom, end, etc.

Sets the gravity of the View or Layout relative to its


parent.
android:layout_gravity
Possible values are – center_vertical, fill, center,
bottom, end, etc.
This must be a boolean value, either “true” or “false”
and prevents the layout
android:baselineAligned
from aligning its children’s baselines.

android:id This gives a unique id to the layout.

Relative Layout :
Relative layout is very powerful layout ,because instead of using multiple linear layouts we can
use relative layout and make our design simple .In relative layout position of the child view is
relative to each other and relative to parent.
We can create relation between child and parents and we can create relation between
Childs(Views).

Figure 2:Android Relative Layout

Important attributes of Relative layout

Sr.No. Attribute & Description

1
android:id
This is the ID which uniquely identifies the layout.
2
android:gravity
This specifies how an object should position its content, on both the X and Y
axes. Possible values are top, bottom, left, right, center, center_vertical,
center_horizontal etc.

3
android:ignoreGravity
This indicates what view should not be affected by gravity.

Students should implement following Program during practical session

A)Write a program to place Name, Age and mobile number linearly (Vertical) on the display screen using
Linear layout.

Steps

1.Open new project in android studio

2.Add linear layout in activity_main.xml file as shown bellow and set orientation to vertical

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

</LinearLayout>
3.Add three text views as shown bellow

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile Number"></TextView>

</LinearLayout>
4.It will show following design

5.Execute application using AVD or using Physical Device

B) Write a program to show three color names with text views on the screen vertically one bellow
other using relative layout.

Steps

1.Open new project in android studio

2.Add relative layout in activity_main.xml file as shown below and set


android:gravity="center"
3.Add three text views with three color names and set

android:layout_below="@id/txt1" for second text view(id is text2)

android:layout_below="@id/txt2" for third text view(id is text3)

4.It will show following code


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

android:gravity="center"
tools:context=".MainActivity">

<TextView
android:id="@+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BLUE"></TextView>
<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORANGE"
android:layout_below="@id/txt1"
></TextView>
<TextView
android:id="@+id/txt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PURPLE"
android:layout_below="@id/txt2"></TextView>

</RelativeLayout>
5.It will show following design
6.Execute application using AVD or Physical device

Conclusion :Linear layout and relative layouts are most basic layouts in
Android ,they are useful to make user interface of any android application.

Experiment No 3
Title: Implement Table Layout, Absolute Layout and Frame Layout
Practical Significance:

To develop and place the android views accurately on the display screen, android provides various
layouts. Various layouts can be used as per the program requirements Table Layout, Absolute Layout and
Frame layout are important layouts in Android UI design.

Relevant Course Outcomes(What you will learn?)

CO 2: . Utilize the appropriate User Interface controls in Android app

Minimum Theoretical Background


Layouts which are subclasses of View Group class and a typical layout defines the visual
structure for an Android user interface .You can create your layout in activity_main.xml which is
located in the res/layout folder of your project. layouts defined in XML file. A layout may
contain any type of widgets such as buttons, labels, textboxes etc. Layout Attributes Each layout
has a set of attributes which define the visual properties of that layout. There are few common
attributes among all the layouts and there are other attributes which are specific to that layout
.Before learning mew layouts you should know how to use linear layout and relative layout in
Android

Table Layout

By using table layout we can arrange views into rows and columns.

You have to use the <TableRow> element to add a row in the table. Each row has one or more
cells; each cell can hold one View .
TableLayout containers do not display border lines for their rows, columns, or cells.

TableLayout Attributes
Following are the important attributes specific to TableLayout −

Sr.No. Attribute & Description

1
android:id
This is the ID which uniquely identifies the layout.

2
android:collapseColumns
This specifies the zero-based index of the columns to
collapse. The column indices must be separated by a
comma: 1, 2, 5.

3
android:shrinkColumns
The zero-based index of the columns to shrink. The
column indices must be separated by a comma: 1, 2, 5.

4
android:stretchColumns
The zero-based index of the columns to stretch. The
column indices must be separated by a comma: 1, 2, 5.

Absolute layout
An Absolute Layout lets you specify exact locations (x/y coordinates) of its children. Absolute
layouts are less flexible and harder to maintain than other types of layouts without absolute
positioning.

AbsoluteLayout Attributes

Following are the important attributes specific to AbsoluteLayout −

Sr.No Attribute & Description


1
android:id
This is the ID which uniquely identifies the layout.

2
android:layout_x
This specifies the x-coordinate of the view.

3
android:layout_y
This specifies the y-coordinate of the view.

Android Frame Layout:


Frame Layout is designed to block out an area on the screen to display a single item. We can add
more view on frame layout the new view will be on top of previous view .We can show one view
on another view using frame layout.

Following are the important attributes specific to FrameLayout −

Sr.No Attribute & Description

1 android:id

This is the ID which uniquely identifies the layout.

2 android:foreground

This defines the drawable to draw over the content and possible values may be a color
value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".

3 android:foregroundGravity

Defines the gravity to apply to the foreground drawable. The gravity defaults to fill.
Possible values are top, bottom, left, right, center, center_vertical, center_horizontal
etc.

4 android:measureAllChildren
Determines whether to measure all children or just those in the VISIBLE or
INVISIBLE state when measuring. Defaults to false.

A)Create following User Interface using Android Table layout

Steps

1.Create new application and give name table layout or any other suitable name

2.Open activity_main.xml file and add table layout in it as shown bellow


<?xml version="1.0" encoding="utf-8"?>
<TableLayout
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">
</TableLayout>
3.Add required rows and views to create above given structure
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
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">

<TableRow>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="WELCOME"
android:layout_weight="1"
android:textAlignment="center"
android:textSize="30dp"
>

</TextView>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RIT"

android:textAlignment="center"
android:textSize="30dp"
>

</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="COLLEGE"
android:layout_weight="1"
android:textAlignment="center"
android:textSize="30dp"
>

</TextView>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="PRN"

android:textAlignment="center"
android:textSize="20dp"
>

</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Name"
android:layout_weight="1"
android:textAlignment="center"
android:textSize="20dp"
>

</TextView>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Address"
android:layout_weight="1"
android:textAlignment="center"
android:textSize="20dp"
>

</TextView>
</TableRow>

<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="12"

android:textAlignment="center"
android:textSize="20dp"
>

</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Amit Patil"
android:layout_weight="1"
android:textAlignment="center"
android:textSize="20dp"
>

</TextView>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sangli"
android:layout_weight="1"
android:textAlignment="center"
android:textSize="20dp"
>

</TextView>
</TableRow>

</TableLayout>

4.Run application using AVD or using any physical device

B)Design Simple Login Form using Absolute layout as shown bellow

Steps

1.Create new application using android studio and give suitable name.

2.Add Absolute layout as shown bellow


<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
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">

</AbsoluteLayout>
3.Add required views as shown bellow
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="41dp"
android:layout_y="10dp"
android:text="LOGIN FORM"
android:textSize="50dp"></TextView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="15dp"
android:layout_y="109dp"
android:text="User Name"
android:textSize="25dp"></TextView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="22dp"
android:layout_y="183dp"
android:text="Password"
android:textSize="25dp"></TextView>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="163dp"
android:layout_y="106dp"
android:width="200dp"
></EditText>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="161dp"
android:layout_y="173dp"
android:width="200dp"></EditText>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="245dp"
android:layout_y="256dp"
android:text="LOGIN"
android:textSize="25dp"></Button>

</AbsoluteLayout>

4.Execute application using AVD or using any physical device

C) Take image and show your full name on that image using frame
layout

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


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

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/nature"
android:scaleType="fitXY"
></ImageView>
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amit Patil PRN 234"
android:textSize="40dp"
android:textColor="#F3EEEF"></TextView>
</FrameLayout>

Conclusion: Table layout ,Absolute layout and Frame layout are useful layouts to design user
friendly user interface

Experiment No 4
Title: Create User interface for signup activity using required layout
and views.
Practical Significance: Views are building blocks for any android application,in this practical
we will learn some important views such as button ,Textview and Edittext

Relevant Course Outcomes(What you will learn?)

CO 2: Utilize the appropriate User Interface controls in Android app

Minimum Background:

Before using different views you must have knowledge of different types of layouts ,such as
Linear layout ,relative layout etc, because layouts works as container for other views and
specifies arrangement for child views
What is Android View?

• A View is a basic building block of a user interface in android. It is a small rectangular


box that can be TextView, EditText, or even a button. It occupies the rectangular area on
the screen so it has height and width

• Views are responsible for generating events due to user interaction

Some important views in Android

• TextView

• EditText

• Button

• Image Button

• Date Picker

• RadioButton

• CheckBox buttons

• Image View

Textview in Android

A TextView displays text to the user and optionally allows them to edit it. A TextView is a
complete text editor, however the basic class is configured to not allow editing.

TextView Attributes

Following are the important attributes related to TextView control. You can check Android
official documentation for complete list of attributes and related methods which you can use to
change these attributes are run time.

Sr.No. Attribute & Description

1
android:id
This is the ID which uniquely identifies the control.
2
android:capitalize
If set, specifies that this TextView has a textual input method and should
automatically capitalize what the user types.

 Don't automatically capitalize anything - 0


 Capitalize the first word of each sentence - 1
 Capitalize the first letter of every word - 2
 Capitalize every character - 3

3
android:editable
If set to true, specifies that this TextView has an input method.

4
android:gravity
Specifies how to align the text by the view's x- and/or y-axis when the text is smaller
than the view.

5
android:text
Text to display.

6
android:textColor
Text color. May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or
"#aarrggbb".

7
android:textSize
Size of the text. Recommended dimension type for text is "sp" for scaled-pixels
(example: 15sp).

8
android:textStyle
Style (bold, italic, bolditalic) for the text. You can use or more of the following values
separated by '|'.

 normal - 0
 bold - 1
 italic - 2
Following is an example of text in the activity_main.xml file
<TextView
android:id="@+id/text_id"
android:layout_width="300dp"
android:layout_height="200dp"
android:capitalize="characters"
android:text="hello_world"
android:textSize="50dp"/>

EditText

A EditText is an overlay over TextView that configures itself to be editable. It is the predefined
subclass of TextView that includes rich editing capabilities.

Important Attributes of EditText

Sr.No Attribute & Description

4 android:editable

If set, specifies that this TextView has an input method.

5 android:text

This is the Text to display.

3
android:id
This supplies an identifier name for this view.

4
android:onClick
This is the name of the method in this View's context to invoke when the view
is clicked.

Example EditText in activity_main.xml file

<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button"
android:layout_below="@+id/textView1"
android:layout_marginTop="61dp"
/>

Button in Android
A Button is a Push-button which can be pressed, or clicked, by the user to perform an action.
Some important attributes of Button are
Sr.No Attribute & Description

1
android:text
This is the Text to display.

2
android:id
This supplies an identifier name for this view.

3
android:onClick
This is the name of the method in this View's context to invoke when the view
is clicked.

Example of Button in the xml file


<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:id="@+id/button"
android:onClick=”my_method”
" />
Students should implement following programs during practical
session
A)Design a signup form as shown below using required views and
layout.(Use color.xml file to set colors and string.xml to set text,make
required validation by using proper input type)

Conclusion :Views are basic building blocks of Android user interface


useful to create interactive Android application
Experiment No 5
Title: Implement concept of Event Handling.
Practical Significance: Relevant Course Outcomes (What you will learn?)

CO 2: Utilize the appropriate User Interface controls in Android app

Minimum Background:

Before working with events you must able to design user interface and able to add views in user
interface, because vies are responsible for generating the events ,for example when user clicks on
the Button view then click event will be generated.

What is event in Android?


Events are a useful way to collect data about a user's interaction with interactive components of
Applications. Like button presses or screen touch etc. The Android framework maintains an
event queue as first-in, first-out (FIFO) basis. You can capture these events in your program and
take appropriate action as per requirements.

There are following three concepts related to Android Event Management −

Event Listeners − An event listener is an interface that contains a single callback method. This
method will be called by the Android framework when the View to which the listener has been
registered is triggered by user interaction with the item in the UI.

Event Listeners Registration − Event Registration is the process by which an Event Handler
gets registered with an Event Listener so that the handler is called when the Event Listener fires
the event.

Event Handlers − When an event happens and we have registered an event listener for the
event, the event listener calls the Event Handlers, which is the method that actually handles the
event.
Some examples Event Listeners & Event Handlers
Event Handler Event Listener & Description

OnClickListener()
onClick() This is called when the user either clicks or touches or focuses upon
any widget like button, text, image etc. You will use onClick() event
handler to handle such event.

OnLongClickListener()
onLongClick() This is called when the user either clicks or touches or focuses upon
any widget like button, text, image etc. for one or more seconds. You
will use onLongClick() event handler to handle such event.

OnFocusChangeListener()
onFocusChange() This is called when the widget looses its focus ie. user goes away
from the view item. You will use onFocusChange() event handler to
handle such event.

OnFocusChangeListener()
onKey() This is called when the user is focused on the item and presses or
releases a hardware key on the device. You will use onKey() event
handler to handle such event.

OnTouchListener()
onTouch() This is called when the user presses the key, releases the key, or any
movement gesture on the screen. You will use onTouch() event
handler to handle such event.

OnMenuItemClickListener()
onMenuItemClick()
This is called when the user selects a menu item. You will use
onMenuItemClick() event handler to handle such event.

onCreateContextMenu() onCreateContextMenuItemListener()
This is called when the context menu is being built(as the result of a
sustained "long click)

Students should implement following Program during practical


A) Create simple Android Application for calculator as shown below
also add functionality for each button.
You can follow following steps
Step 1:Create new android application using android studio
Step 2:Make proper design using relative layout and required views in
the activity_main.xml file as shown in above image.
Step 3:Add required functionality for all the buttons in
MainActivity.java file.
Sample code for +(addition) button is shown below.

package com.example.myapp;

import android.support.v7.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.Toast;

public class MainActivity extends AppCompatActivity {

private EditText editnum1;


private EditText editnum2;
private Button btnadd;
private Button btnsub;
private Button btnmul;
private Button btndiv;
private Button btnclear;
private TextView txtresult;

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

editnum1=(EditText) findViewById(R.id.editnum1);
editnum2 = (EditText) findViewById(R.id.editnum2);
btnadd = (Button) findViewById(R.id.btnadd);
btnsub = (Button) findViewById(R.id.btnsub);
btnmul = (Button) findViewById(R.id.btnmul);
btndiv = (Button) findViewById(R.id.btndiv);
btnclear = (Button) findViewById(R.id.btnclear);
txtresult= (TextView) findViewById(R.id.txtresult);

// Addition
btnadd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//your code starts
if(editnum1.getText().length()>0 && editnum2.getText().length()>0)
{//if start
Double num1=Double.parseDouble(editnum1.getText().toString());
Double num2=Double.parseDouble(editnum2.getText().toString());
Double result=num1+num2;
txtresult.setText(Double.toString(result));
}//if end
else {//
// else start

Toast toast= Toast.makeText(MainActivity.this,"Enter The Required


Numbers",Toast.LENGTH_LONG);
toast.show();

}//else end
//your code ends
}
});

}//default
}//default

Step 4:Add code for other buttons also for subtraction ,multiplication and division
Step 5: Execute application using AVD or using physical device.

Conclusion: Event handling is used to respond properly based on the events generated by the
user using views in Android.
Experiment No 6
Title: Develop a program to implement new activity using explicit
intent and implicit intent.
Practical Significance:

CO 2: Utilize the appropriate User Interface controls in Android app

Minimum Background:

To launch new activity from first activity we must know about intent, intent is a message passed
between two activities or two components, to launch new activity first activity creates intent and
that intent is passed to the second activity, you can pass some data to the second activity using
intent.

What is Activity?

Activity is a single screen with user interface, it plays major role in creation of user interface and
collecting data from the user.

By default you have one activity which is MainActivity with two files MainActivity.java and
activity_main.xml files.MainActivity.java file is used for coding purpose and activity_main.xml
file is used for designing purpose.

After adding new activity you can launch activity by using intent.

Types of intents
There are two types of intents 1)Implicit Intent 2)Explicit Intent

1) Implicit Intent
This intent does not specifies name of target component instead this intent specifies an action
that can be completed by any component in same app or by any other app on the device.
It does not have exact knowledge about the landing component. It can open another app or its
own app's component and many other options exist.

Example of implicit intent

Intent intent=new Intent(Intent.ACTION_VIEW);


intent.setData(Uri.parse("http://www.google.com"));
startActivity(intent);
2)Explicit intent
Specifies the name of exact component to open. For example if we have to launch Activity xyz
then you have to specify exact name of Activity xyz in the intent.

Example of explicit intent

Intent i = new Intent(getApplicationContext(), ActivityTwo.class);


startActivity(i);

In both implicit and explicit intent We have to create object of Intent class to create intent and by
using startActivity() method we can start the activity.

Students should implement following programs during practical


session.
A)Create a simple Android Application using Explicit intent
B)Create Android Application using explicit intent

A)Create a simple Android Application using Explicit intent

Steps :
1)Create new Application using android studio
2)Add new activity to your project as shown bellow
3)open activity_main.xml and write following code
• <?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:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity 1"
android:textSize="30dp"
android:textColor="#9C27B0"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Activity 2"
android:textSize="20dp“
android:onClick="callSecondActivity"></Button>

</LinearLayout>

4)Open MainActivity.java and add following code


• public class MainActivity extends AppCompatActivity {

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

//Write code to call second method


public void callsecondactivity(View view)
{
//First create intent object and specify name of second activity
Intent i=new Intent(getApplicationContext(),MainActivity2.class);

//Pass some data to second activity
i.putExtra("prn", "123");
i.putExtra("name", "Amit Patil");

// start activity using following code


startActivity(i);
}
}

5)Open activity_main2.xaml and design it as shown bellow6)

6)Finally execute application Using AVD or using any physical design


7)Click on the button in activity1 and you will get activity two

B)Create Android Application using explicit intent

Steps
1)Create new Android application using Android studio
2)Yo nedd not to add second activity for implicit intent so don’t add second activity
3)Add following code in 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"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity 1"
android:textSize="30dp"
android:textColor="#9C27B0"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Visit GOOGLE Website"
android:textSize="20dp“
android:onClick="callSecondActivity"></Button>

</LinearLayout>

4)Add following code in MainActivity.java in OnCreate() method

• public class MainActivity extends


AppCompatActivity {

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

//Write code to call second method


public void callsecondactivity(View view)
{
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.google.com"));
startActivity(intent); }
}

Conclusion :Using Intent we can launch new activity, by using explicit intent you have to
specify exact name of activity to launch explicitly and in case of implicit intent we need not to
specify exact name of activity to open ,because in case of implicit intent system automatically
opens application who will handle the intent
Experiment No 7
Title: Develop application for storing data with SQLite and
SharedPreferences
Practical Significance:

CO 3: Develop application for storing data with SQLite and SharedPreferences

Minimum Background:

SQlite is a light weight database used to store relational data, it is lighter version of SQL Server
database. You can perform all the SQL operations with SQLite such as inserting data, selecting
data ,update, delete .SQLite is embedded in to android so it is easy to work with SQLite when
you are developing the android application. Before working with SQLite you must know
different sql queries such as insert, update ,delete and select.

Working with SQLite

To work with data in SQLite we need to create a user defined class that will extend
SQLiteOpenHelper class.The SQLiteOpenHelper class is system defined class which provides
functionalities to work with SQLite.

There are two abstract methods of this SQLiteOpenHelper class that we have to implement in
our class, onUpgrade and onCreate

SharedPreferences is used to work with data of single user ,for example you can keep track of
user login and logout by using SharedPreferences. You can create variable that will store details
of user activity whether user is logged in or logged out .To store data of multiple users
SharedPreferences is not good for that purpose we can use SQLite.

• We can check whether user has logged in or logged out with the help of shared
preferences .

• Here we can create variable ,we will set value of that variable to true if user has logged in
and we can set its value to false if user has logged out.

• Here we can keep track of user login activities


Students should implement following programs during practical session

A)Create a database having name college, create a student table in it with columns
student_id and name .Store data for a student and also show stored data on your activity
by using text views

Steps:
1) Create New Android application using Android studio and give suitable name.

2) Add new java class to your application by right clicking on package name-newjava Class

3) Extend our class with SQLiteOpenHelper class and add all the database functionality to your
class as shown bellow.

Here MyDBhelper is our class

//Mydbhelper.java
package com.example.databaseexample;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

import java.util.ArrayList;

public class Mydbhelper extends SQLiteOpenHelper {

private static final String database_name="college";


private static final int database_version=1;

//Following constructor is used to create database college with version


public Mydbhelper(@Nullable Context context)
{
super(context, database_name, null, database_version);
}

@Override
//In following method we have created table having name student with student_id and
name
public void onCreate(SQLiteDatabase sqLiteDatabase)
{

String create="CREATE TABLE student(student_id INTEGER PRIMARY KEY,name


TEXT NOT NULL)";
sqLiteDatabase.execSQL( create);

}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1)
{

}
//Following function is used to add the student details to database
public void addstudent(int student_id,String name)
{
SQLiteDatabase database=this.getWritableDatabase();
ContentValues values=new ContentValues();
values.put("student_id",student_id);
values.put("name",name);
database.insert("student",null,values);
database.close();
}
//Following function is used to select and view data from student table
public ArrayList<studentdetils> fetchstudents()
{
SQLiteDatabase db=this.getReadableDatabase();
Cursor cursor=db.rawQuery("select * from student",null);
ArrayList<studentdetils> arraydetails= new ArrayList<>();
while (cursor.moveToNext())
{
studentdetils student=new studentdetils();
student.student_id= cursor.getInt(0);
student.name=cursor.getString(1);
arraydetails.add(student);

}
return arraydetails;
}
}

4)Create following student details class by rightclicking package namenew java class

//studentdetails.java
package com.example.databaseexample;

public class studentdetils {

int student_id;
String name;
}
4)In your MainActivity.java create object of above class and call required methods for
insertion and to select the data
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

TextView txtrollno,txtname;

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

Mydbhelper dbhelper=new Mydbhelper(this);


dbhelper.addstudent(1,"Amit Patil");
dbhelper.addstudent(2,"Ganesh Wani");

ArrayList<studentdetils> details= dbhelper.fetchstudents();


//

txtrollno=(TextView) findViewById(R.id.txtrollno);
txtname=(TextView) findViewById(R.id.txtname);
txtrollno.setText(Integer.toString(details.get(0).student_id));
txtname.setText(details.get(0).name.toString());
}
}

5)Contents of MainActivity.java
package com.example.databaseexample;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

TextView txtrollno,txtname;

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

Mydbhelper dbhelper=new Mydbhelper(this);


dbhelper.addstudent(1,"Amit Patil");
dbhelper.addstudent(2,"Ganesh Wani");

ArrayList<studentdetils> details= dbhelper.fetchstudents();


//

txtrollno=(TextView) findViewById(R.id.txtrollno);
txtname=(TextView) findViewById(R.id.txtname);
txtrollno.setText(Integer.toString(details.get(0).student_id));
txtname.setText(details.get(0).name.toString());
}
}

6)Contents of activity_main.xml
<AbsoluteLayout
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:gravity="center"
tools:context=".MainActivity">

<TextView
android:id="@+id/txtrollno"
android:layout_width="212dp"
android:layout_height="43dp"
android:layout_x="185dp"
android:layout_y="133dp"
android:background="#E2E4F1"
android:textColor="@color/purple_200"
android:textSize="30dp"></TextView>

<TextView
android:id="@+id/txtname"
android:layout_width="199dp"
android:layout_height="43dp"
android:layout_x="195dp"
android:layout_y="217dp"
android:background="#E2E4F1"
android:textColor="@color/purple_200"
android:textSize="30dp"></TextView>

<TextView
android:id="@+id/txt"
android:layout_width="154dp"
android:layout_height="43dp"
android:layout_x="10dp"
android:layout_y="137dp"
android:text="Roll NO :"
android:textColor="@color/purple_200"
android:textSize="30dp"></TextView>

<TextView
android:id="@+id/txt1"
android:layout_width="294dp"
android:layout_height="43dp"
android:layout_x="71dp"
android:layout_y="27dp"
android:text="Student Details:"
android:textColor="@color/purple_200"
android:textSize="30dp"></TextView>

<TextView

android:layout_width="154dp"
android:layout_height="43dp"
android:layout_x="11dp"
android:layout_y="222dp"
android:text="Name :"
android:textColor="@color/purple_200"
android:textSize="30dp"></TextView>
</AbsoluteLayout>

B)Create simple Android application to use shared preferences(In following


example if user has opened application for first time then he will login by clicking login button
on first activity .If user opens same application again without logout then he will be redirected to
the second activity(Home page)because he has already logged in.

On Home activity(Second activity)when user clicks on logout button then he will be redirected to
the first activity for login .)

• Step 1:Create new Android studio Project


• Step 2 :Design activity_main.xml file as
• as shown bellow

• <?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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login
android:textColor="@color/purple_500"
android:textSize="30dp"
/>
<Button
android:id="@+id/btnlogin"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text="LOGIN"></Button>

</LinearLayout>

• Step 3:Add second activity to project by right clicking to package new  Empty
Activity .Give home name to activity2.

Step 4 :Design second activity as shown bellow



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="40dp"
tools:context=".home">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home
android:textAlignment="center"
android:textColor="#076C63"
android:textSize="54dp"></TextView>
<Button
android:id="@+id/btnlogout"
android:backgroundTint="@color/teal_700"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:textSize="30dp"
android:text="LOGOUT"></Button>
</LinearLayout>

Step 5:Add following code in oncreate method of first activity

SharedPreferences pref=getSharedPreferences("login",MODE_PRIVATE);
Boolean check=pref.getBoolean("flag",false);

Intent in;
if(check)
{
in=new Intent(getApplicationContext(),home.class);
startActivity(in);

Step 6:Add following code for button click for login button in first activity

public void onClick(View view) {


Intent intent;
SharedPreferences pref=getSharedPreferences("login",MODE_PRIVATE);
//Now to insert key value in shared preference we have to use editor
SharedPreferences.Editor editor=pref.edit();
editor.putBoolean("flag",true);
editor.apply();

intent=new Intent(getApplicationContext(),home.class);
startActivity(intent);
}
Step 7:Add following code in logout button of second activity

public void onClick(View view) {


Intent intent;

SharedPreferences pref=getSharedPreferences("login",MODE_PRIVATE);
//Now to insert key value in shared preference we have to use editor
SharedPreferences.Editor editor=pref.edit();
editor.putBoolean("flag",false);
editor.apply();

intent=new Intent(getApplicationContext(),MainActivity.class);
startActivity(intent);

Conclusion: By using SQLite and Shared preferences we can store and retrieve data for our
application effectively

Experiment No 8

Title: Implement Location and Notification based functionalities


CO 4: Implement Location and Notification based functionalities in Android app

Minimum Background:

• Practical Significance: To access Google MAP in your application first you must register
your application on Google Developer Console and enable API.

• After the registration you can get Google maps API key that you have to use in your
application.

Google map :

• Android provides facility to integrate Google map in our application. Google map
displays your current location, location of any place on the earth, search location etc. We
can also customize Google map according to our requirement.
Types of Google Map

• Normal: This type of map displays typical road map, natural features like river and some
features build by humans.

• Hybrid: This type of map displays satellite photograph data with typical road maps. It
also displays road and feature labels.

• Satellite: Satellite type displays satellite photograph data, but doesn't display road and
feature labels.

• Terrain: This type displays photographic data. This includes colors, contour lines and
labels and perspective shading.

Notification in Android :

A notification is a message you can display to the user outside of your application's normal UI.
When you tell the system to issue a notification, it first appears as an icon in the notification area.
To see the details of the notification, the user opens the notification drawer. Both the notification
area and the notification drawer are system-controlled areas that the user can view at any time.

Step 1 - Create Notification Builder


As a first step is to create a notification builder using NotificationCompat.Builder.build(). You
will use Notification Builder to set various Notification properties like its small and large icons,
title, priority etc.

Step 2 - Setting Notification Properties


Once you have Builder object, you can set its Notification properties using Builder object as per
your requirement. But this is mandatory to set at least following −
 A small icon, set by setSmallIcon()
 A title, set by setContentTitle()
 Detail text, set by setContentText()
Step 3 - Attach Actions
This is an optional part and required if you want to attach an action with the notification. An
action allows users to go directly from the notification to an Activity in your application, where
they can look at one or more events or do further work.
The action is defined by a PendingIntent containing an Intent that starts an Activity in your
application. To associate the PendingIntent with a gesture, call the appropriate method
of NotificationCompat.Builder. For example, if you want to start Activity when the user clicks
the notification text in the notification drawer, you add the PendingIntent by
calling setContentIntent().
Step 4 - Issue the notification
Finally, you pass the Notification object to the system by calling NotificationManager.notify() to
send your notification. Make sure you call NotificationCompat.Builder.build() method on
builder object before notifying it. This method combines all of the options that have been set and
return a new Notification object.

The NotificationCompat.Builder Class


The NotificationCompat.Builder class allows easier control over all the flags, as well as help
constructing the typical notification layouts. Following are few important and most frequently
used methods available as a part of NotificationCompat.Builder class.

Students Should implement following Programs during practical session

A) Create simple Android app to show Google Map

B) Create simple android App to implement notification base functionalities

A) Create simple Android app to show Google Map

Step 1: Create new Android application in Android studio and select Google Map
Activity
Step 2: Open AndroidMenifest.xml file copy URL present in that file or copy following
URL

• https://developers.google.com/maps/documentation/android-sdk/get-api-key

Step 3: Open any web browser and paste it in address bar ,new page will open ,follow the
instructions and finally you will get the API key
Step 4: In your android studio project open local.properties file and at the end add
following line.at the place of “Your API Key” paste your API Key

MAPS_API_KEY="Your API Key"

Example: MAPS_API_KEY="AIzaSyDYa0KX2WeFryn0uuL05KD2R-CQS_IHZuw"

Step 5: Open androidMenifest.xml file and add android: value="${MAPS_API_KEY}"


in <meta-data> tag.

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />

Step 6:Open MapsActivity.java file and do changes as shown in following code to create
Marker, add marker and move camera. In this example we have shown latitude and
longitude of Sydney city, you can use latitude and longitude of any other place
Step 7: Finally execute application and execute it on physical device ,It will show
Google map with given marker.

B) Create simple android App to implement notification base functionalities

Step 1 : Create new Android application and select empty activity


Step 2: Do not make any change to activity_main.xml. Only change text of text view as
shown bellow
<?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"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notification Example!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Step 3: Make changes in MainActivity.java file as shown in following code .When you
execute application this code will show notification “This is new notification”

public class MainActivity extends AppCompatActivity {


public static final String CHANEL_ID="My Chanel";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.bluetooth)
.setContentTitle("This is new notification")
.setContentText("This is a text inside notification");

Intent notificationIntent = new Intent(this, MainActivity.class);


PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);

// Add as notification
NotificationManager manager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());

}
}
Step 4:Execut application and you will see notification in your device
Experiment No 9

Title: Implement concept of web view in Android

CO 4: Design and develop a WebView based Android app

Minimum Background:

Android WebView is used to display a web page in android application . The web page can be
loaded from same application or URL.

It is used to display online contents in android activity.

Android WebView uses webkit engine to display web page.

If you have to create a browser then you can use Webview

To show text there is a textview

To show image there is a image view similarly to show there is a webview .

Facebook has both website and Android app

The loadUrl() of Android WebView class are used to load and display web page.

WebView mywebview = (WebView) findViewById(R.id.webView1);

mywebview.loadUrl("http://www.javatpoint.com/");
Step 1:Create new Android project

Step 2:In xml file Add <webview> Element

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

<WebView
android:id="@+id/webview1"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>

</LinearLayout>

Step 3:Open main Activity.java file Create object of webview class and using object call loadUrl
method ,give address of webpage to open as a parameter

public class MainActivity extends AppCompatActivity {


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

mywebview = (WebView) findViewById(R.id.webview1);


mywebview.loadUrl("https://www.google.com");

mywebview.setWebViewClient(new WebViewClient());

}
}

In above step mywebview.setWebViewClient(new WebViewClient());

is used because when user search something in Google or click on any link the new webpage will
be displayed in the activity .

If you do not add mywebview.setWebViewClient(new WebViewClient());

statement then only specified URL will be displayed in activity and when you click on any other
link then it will not be displayed in your activity, instead it will open web browser on your
Android device

Step 4:Our application needs to take permission to access internet

Open AndroidMenifest.xml file and following permission for internet above <application> tag

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Step 5:Execute the application in virtual or physical device it will show webpage is displayed in
your activity

Conclusion :Webview is very useful to show any webpage into the android application

Experiment No 10

Title: Understand Play store Deployment Process


CO 6: Build and deploy Android app on Google Play Store

Minimum Background: Before starting uploading Android application to Google play store first
we need to create signed apk file,after creation of signed apk file we can upload it to the Google
play console.
Step 1:Create signed apk file

• Signed apk is useful to make changes to your application such as to add new features to
application , remove bugs.

• After changes we create new apk file and upload this new apk file on the play store.

• Play store matches signature of old apk file and new apk file of updated app ,both must
be same.

• If both are same then old application will be replaced by new updated application on the
play store

jks file(java key store).

• Here signature is in the form of jks file

• When we upload application for first time then while creating apk file jks file is created

• This jks file is added to the apk file.

• So with apk file jks file will be uploaded to the play store

• When we make any changes to application then we create new apk file, but jks file is
same that is used by first apk file.

Steps to create signed apk file

• Open your application that you have to upload on Google play store.
Step No 2:Upload your application on play store

1. Open Play Console.


2. Select All apps > Create app.
3. Select a default language and add the name of your app as you want it to appear on
Google Play. You can change this later.
4. Specify whether your application is an app or a game. You can change this later.
5. Specify whether your application is free or paid.
6. Add an email address that Play Store users can use to contact you about this application.
7. In the "Declarations" section:
8. Acknowledge the “Developer Program Policies” and “US export laws” declarations.
9. Accept the Play App Signing Terms of Service.
10. Select Create app.

Set up your app

After you create your app, you can start setting it up. Your app’s dashboard will guide you
through all the most important steps to get your app available on Google Play.

You’ll start by providing details about your app’s content, and entering information for your
Google Play store listing. After that, you can move onto app release; this guides you through
pre-release management, testing, and promotion to build pre-release excitement and awareness.
The final step is launching your app on Google Play, making it available to billions of users.

To start setting up your app, select Dashboard on the left menu. For the next steps, go to Set up
your app on the app dashboard.

Manage your app and app bundles

Google Play uses Android App Bundles to generate and deliver APKs that are optimized for
each device configuration, providing users with more efficient apps. This means you only need
to build, sign, and upload a single app bundle to support optimized APKs for a wide variety of
device configurations. Google Play then manages and serves your app's distribution APKs for
you.

Package names for app files are unique and permanent, so please name them carefully. Package
names can't be deleted or re-used in the future.

Your release can have one of three statuses:

 Draft: APKs that have not been served to users yet


 Active: APKs currently being served to users
 Archived: APKs that were once active but are no longer being served to users
Set up your store listing and settings

Your app's store listing is displayed on Google Play and includes details that help users learn
more about your app. Your store listing is shared across tracks, including testing tracks.

Conclusion :In this practical we learned to how to create signed apk file and how to upload your
application on Google play store

You might also like