Lab Manual MAD CS3163
Lab Manual MAD CS3163
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
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.
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 FileNew->New Project
In the new project window select empty activity and click next
To execute your application you must have to create AVD (Android Virtual Device) or you can
use your personal physical smart android phone
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.
Using ADB we can run app on real physical device(On Mobile phone)
Select system image for your phone(Select latest version id not available click on download,
internet must be on)
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.
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
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).
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.
A)Write a program to place Name, Age and mobile number linearly (Vertical) on the display screen using
Linear layout.
Steps
2.Add linear layout in activity_main.xml file as shown bellow and set orientation to vertical
</LinearLayout>
3.Add three text views as shown bellow
<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
B) Write a program to show three color names with text views on the screen vertically one bellow
other using relative layout.
Steps
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.
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 −
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
2
android:layout_x
This specifies the x-coordinate of the view.
3
android:layout_y
This specifies the y-coordinate of the view.
1 android:id
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.
Steps
1.Create new application and give name table layout or any other suitable name
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>
Steps
1.Create new application using android studio and give suitable name.
</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>
C) Take image and show your full name on that image using frame
layout
<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
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?
• 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.
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.
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.
4 android:editable
5 android:text
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.
<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.
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.
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)
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;
@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
}//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:
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.
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.
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>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
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>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
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:
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.
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.
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-newjava Class
3) Extend our class with SQLiteOpenHelper class and add all the database functionality to your
class as shown bellow.
//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;
@Override
//In following method we have created table having name student with student_id and
name
public void onCreate(SQLiteDatabase sqLiteDatabase)
{
}
@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 namenew java class
//studentdetails.java
package com.example.databaseexample;
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;
TextView txtrollno,txtname;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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;
TextView txtrollno,txtname;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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>
On Home activity(Second activity)when user clicks on logout button then he will be redirected to
the first activity for login .)
</LinearLayout>
• Step 3:Add second activity to project by right clicking to package new Empty
Activity .Give home name to activity2.
<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>
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
intent=new Intent(getApplicationContext(),home.class);
startActivity(intent);
}
Step 7:Add following code in logout button of second activity
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
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 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
Example: MAPS_API_KEY="AIzaSyDYa0KX2WeFryn0uuL05KD2R-CQS_IHZuw"
<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.
<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”
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.bluetooth)
.setContentTitle("This is new notification")
.setContentText("This is a text inside notification");
// 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
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.
The loadUrl() of Android WebView class are used to load and display web page.
mywebview.loadUrl("http://www.javatpoint.com/");
Step 1:Create new Android project
<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
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 .
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
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
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
• When we upload application for first time then while creating apk file jks file is created
• 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.
• Open your application that you have to upload on Google play store.
Step No 2:Upload your application on play store
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.
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 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