6sem Mad Lab Manual
6sem Mad Lab Manual
Gramothan, Jaipur
Lab Manual
Semester: VI
Session 2022-23
Faculty:
VERSION 1.0
Pawan Kumar
Patidar
Assistant Professor
Associate professor
SIGNATURE
LAB ETHICS
DO’s
1. Please switch off the Mobile/Cell phone before entering Lab.
2. Enter the Lab with complete source code and data.
3. Check whether all peripheral are available at your desktop before proceeding for program.
4. Intimate the lab In charge whenever you are incompatible in using the system or in case
software get corrupted/ infected by virus.
5. Arrange all the peripheral and seats before leaving the lab.
6. Properly shutdown the system before leaving the lab.
7. Keep the bag outside in the racks.
8. Enter the lab on time and leave at proper time.
9. Maintain the decorum of the lab.
10. Utilize lab hours in the corresponding experiment.
11. Get your Cd / Pendrive checked by lab In charge before using it in the lab.
Don’ts
1. No one is allowed to bring storage devices like Pan Drive /Floppy etc. in the lab.
2. Don’t mishandle the system.
3. Don’t leave the system on standing for long
4. Don’t bring any external material in the lab.
5. Don’t make noise in the lab.
6. Don’t bring the mobile in the lab. If extremely necessary then keep ringers off.
7. Don’t enter in the lab without permission of lab Incharge.
8. Don’t litter in the lab.
9. Don’t delete or make any modification in system files.
10. Don’t carry any lab equipments outside the lab
INSTRUCTIONS
Marking Scheme
Total Marks- 75
Internal Assessment Marks Distribution
Attendance File Work Performance Viva Total
5 10 20 10 45
5 15 10 30
List of Experiments
2 To develop a Simple Android Application that uses Layout Managers and Event
Listeners.
3 Design simple GUI application with activity and intents e.g. calculator
Android Studio is a new and fully integrated development environment, which has been recently
launched by Google for the Android operating system. It has been designed to provide new tools
for app development and to provide an alternative to Eclipse, currently the most widely used
IDE. When you begin a new project in Android studio, the project's structure will appear with
almost all the files held within the SDK directory, this switch to a Gradle based management
system offers an even greater flexibility to the build process.
Android Studio allows you to see any visual changes you make to your app in real-time, and you
can also see how it will look on a number of different Android devices, each with different
configurations and resolutions, simultaneously. Another feature in Android Studio are the new
tools for the packing and labelling of code. These let you keep on top of your project when
dealing with large amounts of code. The programme also uses a drag & drop system to move the
components throughout the user interface.
The programme will also help you to localize your apps, giving you a visual way to keep
programming while controlling the flow of the application.
- Wizards and templates for common elements found in all Android programming.
- A full-featured editor with lots of extra tools to speed up the development of your applications.
Android UI Controls: There are number of UI controls provided by Android that allow you to
build the graphical user interface for your app.
1
• ToggleButton:: An on/off button with a light indicator.
• RadioButton:: The RadioButton has two states: either checked or unchecked.
• Spinner::A drop-down list that allows users to select one value from a set.
Android Event Handling : Events are a useful way to collect data about a user's interaction
with interactive components of your app, like button presses or screen touch etc. The Android
framework maintains an event queue into which events are placed as they occur and then each
event is removed from the queue on a 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: The View class is mainly involved in building up a Android GUI, same
View class provides a number of Event Listeners. The Event Listener is the object that receives
notification when an event happens.
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 and event listener for the
event, the event listener calls the Event Handlers, which is the method that actually handles the
event.
2
Download Android Studio
Google provides Android Studio for the Windows, Mac OS X, and Linux platforms. You can
download Android Studio from the Android Studio homepage, where you'll also find the
traditional SDKs with Android Studio's command-line tools. Before downloading Android
Studio, make sure your platform meets the following requirements:
Windows requirements
Clicking Next took to the following panel, which provides the option to decline installing an
Android Virtual Device (AVD).
3
Keep the default settings. After clicking Next, Configuration Settings panel will be open, where
you have to choose where to install Android Studio.
Keep the default installation location and click Next, this will open Choose Start Menu Folder
panel.
4
Keep the default setting and click Install. The following Installing panel appeared:
Clicking Show details causes the names of files being installed and other activities to be
displayed. When installation finished, the Installation Complete panel appeared.
5
After clicking Next, the installer presented the Completing Android Studio Setup panel.
To complete the installation, I left the Start Android Studio box checked and clicked Finish.
6
Running Android Studio
The first time Android Studio runs, it presents a Complete Installation dialog box that offers the
option of importing settings from a previous installation.
Choose not to import settings (the default selection) and clickOK, and the following splash
screen will be displayed:
At this point, Android Studio presented the following Android Studio Setup Wizard dialog box:
7
Click Next, and the wizard invited you to select an installation type. Keep the default standard
setting.
8
You will be directed to the page to choose a user interface theme.
Keep the default IntelliJ setting and click Next. Android Studio next provided the opportunity to
verify settings.
9
Click Finish and Android Studio began the process of downloading SDK components.
Finally, Click Finish to complete the wizard. The Welcome to Android Studio dialog box
appeared.
10
Starting a new project
click Start a new Android Studio project. Android Studio will respond with the
Create New Project dialog box shown in Figure
11
Select language as Java, name your activity and package and click on finish. This will launch the
basic activity project.
RUN Application
To run your application in android studio you have two options.
1. either use a real device and connect it via USB cable .and run the application on it
2. or create a AVD in android(Tools->AVD manager-> create virtual device) and run application
on this emulator.
12
Experiment-1
Aim: To develop a Simple Android Application that uses GUI components, Font and
Colors
Procedure:
◾ Open Android Stdio and then click on File -> New -> New project.
◾ Then select the Minimum SDK as shown below and click Next.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
13
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:gravity="center"
android:text="Hello World!"
android:textSize="25sp"
android:textStyle="bold" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:textSize="25sp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:gravity="center"
android:text="Change color"
14
android:textSize="25sp" />
</LinearLayout>
MainActivity.java
package com.example.exno1;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
int ch=1;
float font=30;
@Override
super.onCreate(savedInstanceState);
15
setContentView(R.layout.activity_main);
b1.setOnClickListener(new View.OnClickListener() {
@Override
t.setTextSize(font);
font = font + 5;
if (font == 50)
font = 30;
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
switch (ch) {
case 1:
t.setTextColor(Color.RED);
break;
case 2:
t.setTextColor(Color.GREEN);
break;
case 3:
t.setTextColor(Color.BLUE);
16
break;
case 4:
t.setTextColor(Color.CYAN);
break;
case 5:
t.setTextColor(Color.YELLOW);
break;
case 6:
t.setTextColor(Color.MAGENTA);
break;
ch++;
if (ch == 7)
ch = 1;
});
17
Experiment-2
Aim: To develop a Simple Android Application that uses Layout Managers and Event
Listeners.
Procedure:
◾ Open Android Studio and then click on File -> New -> New project.
◾ Then select the Minimum SDK as shown below and click Next.
18
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Login">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp">
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login_details"
android:gravity="center"
android:textSize="30dp"
android:layout_margin="30dp"/>
</LinearLayout>
<GridLayout
android:id="@+id/gridl"
android:layout_height="match_parent"
19
android:layout_width="match_parent"
android:columnCount="2"
android:rowCount="3"
android:layout_marginTop="100dp"
android:layout_marginBottom="200dp">
<TextView
android:id="@+id/utext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="username"
android:layout_margin="20dp"
android:layout_row="0"
android:layout_column="0"
android:textSize="20sp"/>
<TextView
android:id="@+id/ptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="password"
android:layout_margin="20dp"
android:layout_marginTop="5dp"
android:layout_row="1"
android:layout_column="0"
android:textSize="20sp"/>
20
<EditText
android:id="@+id/uet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_row="0"
android:layout_column="1"
android:inputType="textWebEditText"/>
<EditText
android:id="@+id/pet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_row="1"
android:layout_column="1"
android:inputType="textPassword"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
21
android:layout_marginLeft="30dp"
android:layout_row="2"
android:layout_column="0"
android:text="submit details"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:layout_marginLeft="70dp"
android:layout_row="2"
android:layout_column="1"
android:text="reset" />
</GridLayout>
</RelativeLayout>
<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"
22
android:layout_height="match_parent"
tools:context=".Main2Activity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bt"
android:layout_gravity="center"
android:text="LOGOUT"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv1"
android:layout_margin="40dp"
android:text="new text"
android:textSize="30sp"/>
</LinearLayout>
package com.garima.login;
23
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
EditText username,password;
Button l_button,r_button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username=(EditText)findViewById(R.id.uet);
password=(EditText)findViewById(R.id.pet);
l_button=(Button)findViewById(R.id.button);
r_button=(Button)findViewById(R.id.button1);
l_button.setOnClickListener(new View.OnClickListener() {
@Override
24
if(username.getText().toString().equals("admin")&&
password.getText().toString().equals("1234"))
Toast t= Toast.makeText(Login.this,"redirecting",Toast.LENGTH_SHORT);
t.show();
startActivity(i);
else {
Toast.LENGTH_SHORT).show();
});
r_button.setOnClickListener(new View.OnClickListener() {
@Override
username.setText(null);
password.setText(null);
//finish();
});
25
◾ So now the Coding part of Main Activity is completed.
package com.garima.login;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
TextView t1;
Button b1;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
t1=(TextView)findViewById(R.id.tv1);
Intent i1=getIntent();
b1=(Button)findViewById(R.id.bt);
b1.setOnClickListener(new View.OnClickListener() {
26
@Override
startActivity(i);
finish();
});
OUTPUT
27
Experiment-3
Design simple GUI application with activity and intents e.g. calculator
Procedure:
• Open Android Stdio and then click on File -> New -> New project.
• Then select the Empty Activity and click Next.
• Then type the Application name as “ex.no.3″ , select the Minimum SDK and select
language as Java click Finish.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
28
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textSize="20sp" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="numberDecimal"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp">
<Button
android:id="@+id/Add"
android:layout_width="match_parent"
29
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+"
android:textSize="30sp"/>
<Button
android:id="@+id/Sub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-"
android:textSize="30sp"/>
<Button
android:id="@+id/Mul"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*"
android:textSize="30sp"/>
<Button
android:id="@+id/Div"
android:layout_width="match_parent"
android:layout_height="wrap_content"
30
android:layout_weight="1"
android:text="/"
android:textSize="30sp"/>
</LinearLayout>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Answer is"
android:textSize="30sp"
android:gravity="center"/>
</LinearLayout>
Click on app -> java -> com.example.exno3 -> MainActivity. And write the following code
package com.example.devang.exno3;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
31
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
EditText Num1;
EditText Num2;
Button Add;
Button Sub;
Button Mul;
Button Div;
TextView Result;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
32
Sub = (Button) findViewById(R.id.Sub);
// set a listener
Add.setOnClickListener(this);
Sub.setOnClickListener(this);
Mul.setOnClickListener(this);
Div.setOnClickListener(this);
@Override
float num1 = 0;
float num2 = 0;
float result = 0;
if (TextUtils.isEmpty(Num1.getText().toString()) ||
TextUtils.isEmpty(Num2.getText().toString()))
return;
num1 = Float.parseFloat(Num1.getText().toString());
num2 = Float.parseFloat(Num2.getText().toString());
33
// defines the button that has been clicked and performs the corresponding operation
switch (v.getId())
case R.id.Add:
oper = "+";
break;
case R.id.Sub:
oper = "-";
break;
case R.id.Mul:
oper = "*";
break;
case R.id.Div:
oper = "/";
break;
default:
break;
34
Result.setText(num1 + " " + oper + " " + num2 + " = " + result);
Output::
35
36
Experiment-4
Aim: Develop an application that makes use of RSS Feed.
Procedure:
• Open Android Studio and then click on File -> New -> New project.
• Then select the Empty Activity and click Next.
• Then type the Application name as “ex.no.6″, select the Minimum SDK and select
language as Java then click Finish.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
37
Code for AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exno6" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
package com.example.exno6;
38
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
List headlines;
List links;
@Override
39
{
super.onCreate(savedInstanceState);
new MyAsyncTask().execute();
@Override
try
factory.setNamespaceAware(false);
xpp.setInput(getInputStream(url), "UTF_8");
40
{
if (eventType == XmlPullParser.START_TAG)
if (xpp.getName().equalsIgnoreCase("item"))
insideItem = true;
else if (xpp.getName().equalsIgnoreCase("title"))
if (insideItem)
else if (xpp.getName().equalsIgnoreCase("link"))
if (insideItem)
insideItem=false;
41
}
catch (MalformedURLException e)
e.printStackTrace();
catch (XmlPullParserException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
return null;
setListAdapter(adapter);
@Override
42
{
startActivity(intent);
try
return url.openConnection().getInputStream();
catch (IOException e)
return null;
Output
43
44
Experiment-5
Aim: Write an application that draws basic graphical primitives on the screen
Procedure:
• Open Android Studio and then click on File -> New -> New project.
• Then select the Empty Activity and click Next.
• Then type the Application name as “ex.no.5″, select the Minimum SDK and select
language as Java then click Finish.
Click on app -> res -> layout -> activity_main.xml and write the following code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>
package com.example.exno5;
45
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating a Bitmap
i.setBackgroundDrawable(new BitmapDrawable(bg));
46
//Creating the Canvas Object
//Creating the Paint Object and set its color & TextSize
paint.setColor(Color.BLUE);
paint.setTextSize(50);
47
• So now the Coding part is also completed.
• Now run the application to see the output.
Output:
48
Experiment-6
Aim: Create an android app for database creation using SQlite Database
Procedure:
• Open Android Studio and then click on File -> New -> New project.
• Then select the Empty Activity and click Next.
• Then type the Application name as “databaseactivity ″, select the Minimum SDK and
select language as Java then click Finish
• Click on app -> res -> layout -> activity_main.xml and write the following code
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="50dp"
android:layout_y="20dp"
android:text="Student Details"
android:textSize="30sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
49
android:layout_x="20dp"
android:layout_y="110dp"
android:text="Enter Rollno:"
android:textSize="20sp" />
<EditText
android:id="@+id/Rollno"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="100dp"
android:inputType="number"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="160dp"
android:text="Enter Name:"
android:textSize="20sp" />
<EditText
android:id="@+id/Name"
android:layout_width="150dp"
50
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="150dp"
android:inputType="text"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="210dp"
android:text="Enter Marks:"
android:textSize="20sp" />
<EditText
android:id="@+id/Marks"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="175dp"
android:layout_y="200dp"
android:inputType="number"
android:textSize="20sp" />
<Button
android:id="@+id/Insert"
51
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="300dp"
android:text="Insert"
android:textSize="30dp" />
<Button
android:id="@+id/Delete"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="300dp"
android:text="Delete"
android:textSize="30dp" />
<Button
android:id="@+id/Update"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="25dp"
android:layout_y="400dp"
android:text="Update"
android:textSize="30dp" />
52
<Button
android:id="@+id/View"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_x="200dp"
android:layout_y="400dp"
android:text="View"
android:textSize="30dp" />
<Button
android:id="@+id/ViewAll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="100dp"
android:layout_y="500dp"
android:text="View All"
android:textSize="30dp" />
</AbsoluteLayout>
Click on app -> java -> com.garima.databaseactivity -> MainActivity and write the following
code.
package com.garima.databaseactivity;
53
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
EditText Rollno,Name,Marks;
Button Insert,Delete,Update,View,ViewAll;
SQLiteDatabase db;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Rollno=(EditText)findViewById(R.id.Rollno);
Name=(EditText)findViewById(R.id.Name);
54
Marks=(EditText)findViewById(R.id.Marks);
Insert=(Button)findViewById(R.id.Insert);
Delete=(Button)findViewById(R.id.Delete);
Update=(Button)findViewById(R.id.Update);
View=(Button)findViewById(R.id.View);
ViewAll=(Button)findViewById(R.id.ViewAll);
Insert.setOnClickListener(this);
Delete.setOnClickListener(this);
Update.setOnClickListener(this);
View.setOnClickListener(this);
ViewAll.setOnClickListener(this);
if(view==Insert)
if(Rollno.getText().toString().trim().length()==0||
55
Name.getText().toString().trim().length()==0||
Marks.getText().toString().trim().length()==0)
return;
"','"+Marks.getText()+"');");
clearText();
if(view==Delete)
if(Rollno.getText().toString().trim().length()==0)
return;
if(c.moveToFirst())
56
showMessage("Success", "Record Deleted");
else
clearText();
if(view==Update)
if(Rollno.getText().toString().trim().length()==0)
return;
if(c.moveToFirst()) {
else {
57
showMessage("Error", "Invalid Rollno");
clearText();
if(view==View)
if(Rollno.getText().toString().trim().length()==0)
return;
if(c.moveToFirst())
Name.setText(c.getString(1));
Marks.setText(c.getString(2));
else
clearText();
58
}
if(view==ViewAll)
if(c.getCount()==0)
return;
while(c.moveToNext())
buffer.append("Rollno: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("Marks: "+c.getString(2)+"\n\n");
builder.setCancelable(true);
builder.setTitle(title);
59
builder.setMessage(message);
builder.show();
Rollno.setText("");
Name.setText("");
Marks.setText("");
Rollno.requestFocus();
Output::
60
61
Experiment-7
Aim: Develop a native application that uses GPS location information
• Open Android Studio and then click on File -> New -> New project.
• Then select the Map Activity and click Next.
• Then type the Application name as “MapsActivity″, select the Minimum SDK and select
language as Java then click Finish
• Click on app -> res -> layout -> activity_maps.xml and write the following code
Activity_maps.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="hello" />
</RelativeLayout>
62
• Now include the ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION,
INTERNET permissions in the AndroidManifest.xml file as shown below
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.garima.mapactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.garima.mapactivity.MainActivity"
android:label="@string/app_name" >
<intent-filter>
63
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package com.garima.mapactivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.widget.TextView;
import android.util.Log;
TextView txtLat;
64
String lat;
String provider;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
@Override
@Override
Log.d("Latitude","disable");
@Override
Log.d("Latitude","enable");
65
}
@Override
Log.d("Latitude","status");
Output:
66
Experiment-8
Aim: Implement an application that writes data on the SD card.
Procedure:
• Open Android Studio and then click on File -> New -> New project.
• Then select the Empty Activity and click Next.
• Then type the Application name as “ex.no.8″, select the Minimum SDK and select
language as Java then click Finish
• Click on app -> res -> layout -> activity_main.xml and write the following code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30dp" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
67
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Write Data"
android:textSize="30dp" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Read data"
android:textSize="30dp" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Clear"
android:textSize="30dp" />
</LinearLayout>
68
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exno9" >
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
package com.example.exno8;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
69
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
EditText e1;
Button write,read,clear;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
write.setOnClickListener(new View.OnClickListener()
70
@Override
String message=e1.getText().toString();
try
f.createNewFile();
fout.write(message.getBytes());
fout.close();
Toast.makeText(getBaseContext(),"Data Written in
SDCARD",Toast.LENGTH_LONG).show();
catch (Exception e)
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
});
read.setOnClickListener(new View.OnClickListener()
@Override
71
{
String message;
try
buf += message;
e1.setText(buf);
br.close();
fin.close();
catch (Exception e)
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
});
72
clear.setOnClickListener(new View.OnClickListener()
@Override
e1.setText("");
});
OUTPUT:
73
74
Experiment-9
Aim: Design a StopWatch application
Procedure:
• Open Android Studio and then click on File -> New -> New project.
• Then select the Empty Activity and click Next.
• Then type the Application name as “stopwatch″, select the Minimum SDK and select
language as Java then click Finish
• Click on app -> res -> layout -> activity_main.xml and write the following code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/tv1"
android:layout_marginTop="50dp"
android:layout_marginLeft="150dp"
android:gravity="center"
75
android:textSize="30sp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:text="START"
android:layout_marginTop="200dp"
android:layout_marginLeft="150dp"
android:onClick="onClickStart"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b2"
android:text="STOP"
android:layout_marginTop="300dp"
android:layout_marginLeft="150dp"
android:onClick="onClickStop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b3"
android:text="RESET"
android:layout_marginTop="400dp"
android:layout_marginLeft="150dp"
76
android:onClick="onClickReset"/>
</RelativeLayout>
package com.garima.stopwatch;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;
boolean running,wasRunning;
TextView txtv;
Handler hl;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState!=null)
77
{
seconds=savedInstanceState.getInt("seconds");
running=savedInstanceState.getBoolean("running");
wasRunning=savedInstanceState.getBoolean("wasRunning");
runTimer();
super.onPause();
wasRunning=running;
running=false;
super.onResume();
if(wasRunning)
running=true;
@Override
savedInstancestate.putInt("seconds",seconds);
78
savedInstancestate.putBoolean("running",running);
savedInstancestate.putBoolean("wasRunning",wasRunning);
running=true;
running=false;
running=false;
seconds=0;
txtv=(TextView)findViewById(R.id.tv1);
hl=new Handler();
hl.post(new Runnable() {
@Override
int hours=seconds/3600;
int minutes=(seconds%3600)/60;
int secs=seconds%60;
79
String time=String.format("%d:%02d:%02d",hours,minutes,secs);
txtv.setText(time);
if(running)
seconds++;
hl.postDelayed(this,100) ;
});
OUTPUT
80
Experiment-10
Aim: Create an application to play video in android.
Procedure:
• Open Android Studio and then click on File -> New -> New project.
• Then select the Empty Activity and click Next.
• Then type the Application name as “videoact″, select the Minimum SDK and select
language as Java then click Finish
• Click on app -> res -> layout -> activity_main.xml and write the following code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.garima.videoact.MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
81
android:id="@+id/btnPlay"
android:onClick="playVideo" />
<VideoView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/videoView" />
</LinearLayout>
</RelativeLayout>
package com.garima.videoact;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.MediaController;
import android.widget.VideoView;
import androidx.appcompat.app.AppCompatActivity;
VideoView vid;
@Override
super.onCreate(savedInstanceState);
82
setContentView(R.layout.activity_main);
vid = (VideoView)findViewById(R.id.videoView);
vid.setMediaController(m);
Uri u = Uri.parse(path);
vid.setVideoURI(u);
vid.start();
83
Viva Voice
What is Android?
Android is a stack of software for mobile devices which includes an Operating System,
middleware and some key applications. The application executes within its own process and its
own instance of Dalvik Virtual Machine.
To develop a mobile application, Android developers require some tools and this requirement is
satisfied by “Android SDK” which is a set of tools that are used for developing or writing apps.
It has a Graphical User Interface that emulates the Android environment. This emulator acts like
an actual mobile device on which the developers write their code and then debug/test the same
code to check if anything is wrong.
Version Name
Android 8.0 Oreo
Android 7.0 – 7.1.2 Nougat
Android 6 – 6.0.1 Marshmallow
Android 5 – 5.1.1 Lollipop
Android 4.4 – 4.4.4 KitKat
Android 4.1 – 4.3 Jelly Bean
Android 4.0-4.0.4 Ice Cream Sandwich
What is the difference between Mobile Application Testing and Mobile Testing?
Mobile app testing is the testing of applications on a device which mainly focuses on functions
and features of the application. And Mobile Testing is the testing of the actual mobile device and
focuses on mobile features like Call, SMS, Contacts, Media Player, inbuilt browsers, etc.
Java is the widely used language for Android development. It also supports Kotlin and when
used with Android SDK, it improves the performance speed too.
84
Whenever a new Android project is created, the below components are required:
Activities are the part of the mobile app which the user can see and interact with. For Example, if
you open an SMS app which has multiple activities like create new SMS, add a contact from the
address book, write the content in the SMS body, send SMS to the selected contact, etc.Activity
keeps a track of the following:
85
What is an Intent?
Android has an Intent class when the user has to navigate from one activity to another. Intent
displays notifications from the device to the user and then the user can respond to the notification
if required.
Given below are the two types:
• Implicit Intents
• Explicit Intents
What is ADB?
Answer: Android Debug Bridge (ADB) is a command-line tool that performs shell commands.
ADB is used for direct communication between the emulator ports. It gives direct control of the
communication between the emulator instances to the developer.
What is ActivityCreator?
ActivityCreator is a batch file and shell script which was used to create a new Android project.
It is now replaced by the “Create New Project” in Android SDK.
What is Orientation?
Answer: Orientation is the key feature in Smartphones nowadays. It has the ability to rotate the
screen between Horizontal or Vertical mode.
Android supports two types of screen Orientations as mentioned below:
• Portrait: When your device is vertically aligned.
• Landscape: When your device is horizontally aligned.
setOrientation() is a method using which you can set a screen alignments. HORIZONTAL and
VERTICAL are two values that can be set in the setOrientation() method. Whenever there is a
change in the display orientation i.e. from Horizontal to Vertical or vice versa then onCreate()
method of the Activity gets fired.
Basically, when the orientation of the Android mobile device gets changed then the current
activity gets destroyed and then the same activity is recreated in the new display orientation.
Android developers define the orientation in the AndroidManifest.xml file.
What is AIDL?
In the Android platform, there are remote methods that facilitate the use of methods from one
program to another. To create and implement the remote methods the first step is to define the
communication interface in AIDL.
87
AIDL stands for Android Interface Definition Language. It facilitates communication between
the client and the service. It also communicates the information through inter-process
communication. For communication between processes, the data is broken down into chunks
which are easily understandable by the Android platform.
Which scenario can test only on real devices but not on an emulator?
Emulators are used for performing similar kinds of testing which is performed on the real
devices. Basically, emulators are used as a replacement for real devices as sometimes real
88
devices are not available for testing, the use of real mobile devices for testing purposes is costlier
at times.
But there are few scenarios that cannot be tested using emulator, these can be tested only using
real devices. These scenarios are interrupted scenarios i.e. message, phone call interruption while
using the app, low battery, Bluetooth, memory card mount and unmount, etc.
What is DDMS?
Android Studio has debugging tools known as DDMS i.e. Dalvik Debug Monitor Server.
It has wide debugging features which include:
• Port forwarding services.
• Screen capture on the device.
• Thread and Heap information.
• Incoming call and SMS spoofing.
• Logcat
• Radio state information.
• Location data spoofing.
DDMS is integrated with the Android studio. To launch the DDMS, you need to open the
Android Device Monitor (ADM) first and then click on the DDMS menu button. Once DDMS is
launched, then on the left-hand side the list of connected devices is displayed along with the
processes which are running on each device.
With the help of DDMS, you can debug both on real devices and emulators.
89
What are the different data storage options available on the Android platform?
Android platform provides a wide range of data storage options. These options must be used
based on the need such as data is secure and used with permission only or can be accessed
publicly.
Below is the list of data storage options on the Android platform:
• SharedPreference: It stores data in XML files. It is the simplest way to store private data
in the key-value pair.
• SQLite: It stores structured data in the private database.
• Internal Storage: It stores data in the device file system and any other app cannot read
this data.
• External Storage: Data is stored in the file system but it is accessible to all apps in the
device
Explain Sensors in Android.
Android-enabled devices have built-in Sensors that measure Orientation, Motion and other
conditions.
These sensors provide data with high accuracy, which will help to monitor the positioning and
movement of the device. Some of the sensors are hardware-based and few are software-based.
startActivity(intent);
91
Text Books & References
1. https://developer.android.com/studio
2.“Head First Android Development: A Brain-Friendly Guide” by Dawn Griffiths & David Griffiths
O’Relliy publication
92