Beruflich Dokumente
Kultur Dokumente
PRACTICAL RECORD
By
( ) , 2019
1
Department of Computer Science
SACRED HEART COLLEGE, THEVARA
Certificate
Date:
Overview of Android
Android is a mobile operating system developed by Google. It is based on the Linux kernel
designed primarily for touch screen mobile devices such as smart phones and tablets. In recent
days Google has also expanded the range of Android platform apart from mobile devices. They
further develop Android TV for televisions, Android Auto for cars, and Android Wear for
wrist watches. Each has their special User Interface.
Android is not an ‘Android application’ or ‘programming language’ or something else. It’s a
specially designed OS for mobile devices. And also an open source, which means all the source
codes are available to everyone, no need to pay for anyone to develop the app but can sell the
app.
Android is based on Linux: The programmers took the Linux kernel and modified it. They
modified by adding required features and removing unwanted features.Finally what we have got
is Android OS.
Android is a software bundle comprising not only operating system but also middle- ware
and key applications.
Open source, which means all the source codes are available to everyone on free of cost. Its
great for all buddy programmers to practise and develop their own program with- out paying a
single penny for the software or for launching.
HISTORY
Android, Inc. was founded in Palo Alto, California in October 2003 by Andy Rubin and his
team. The early intentions of the company were to develop an advanced operating system for
digital cameras. Later the idea got diverted to develop an Operating System for Mobiles which
could override Symbian and Windows phones. On July 2005, Google acquired Android Inc and
helped the team in their development. The team proved them- selves by launching its first
product named Android, a mobile device platform built on the Linux kernel on November 5,
2007.
Andy Rubin is known as the “Father of Android”. Google was financially supporting
“Android INC” until it was acquired by it.
3
Android application is developed using Android SDK, which includes tools and APIs. To
shorten development time, Android developers typically integrate the SDK into graphical user
IDEs (Integrated Development Environments).
Android Components
The following are the components of Android or the basic building blocks of Android:
• Activity - User interacts with the application through this activity. Activity is a single
window which consists of views like Button, Edit Text, Text View,etc. which is
directly interacted by the user.
• Intent - It is a messaging object that requests an operation to be performed by an another
app component.
• Broadcast receivers - It allows to register and listen for device orientation changes.
• Services- It is an Android component that runs in the background without any user
interaction or interface.
Android Features
An Android device comes with numerous features, for example making a phone call,
sending SMS, and lots more options are there when we use internet through it. The
following are the main features of Android OS:
• Application Framework : Android Application Framework is defined as a collection of
classes, libraries etc which are used in developing or solving an issue in a program. Android
Framework is a bind of Android SDK and various API libraries which are used to develop
new applications using JAVA language on Android Platforms. Android Framework is so
efficient and faster than other Frameworks.
• Dalvik Virtual Machine : Fastest interpreter to run dex files. DVM which have t has
the same functionality as JVM, but works only on Mobile Platform. It consumes less
memory and provides faster performance.
• SQLite : Android comes in with built-in SQLite database implementation.SQLite, a open
source SQL database which stores data to a text file on a device.
• Media Support : Android has inbuilt classes that can manage various audio and video
formats like Mp3, MIDI etc. Unique Media Api39;s are used to access these media files.
These API39;s are used to play Music, ringtones, videos etc.
• Optimized Graphics : Android has inbuilt classes that support optimized graphics VGA,
2D and 3D. Android equips custom 2D graphics library and 3D graphics based on the
OpenGL ES 1.0 specification
4
Contents
1 Hello World
2 Square of an Integer
3 String Swapper
4 Simple Calculator
5 Unit Converter
6 List layout
7 Intent
8 Shared Preferences
9 File
10 Database
11 Contact Application
12 Notification
5
1.Hello World
Aim
Create an android application to display “Hello World”.
activity main.xml
<?xml version="1.0"encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://
schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.example.user.helloworld.MainActivity">
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.user.helloworld;
publicclassMainActivityextendsAppCompatActivity{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
}
}
6
Output
Result
Program has been executed successfully and output is obtained.
7
2.Square of an Integer
Aim
Create an android application to find the square of an integer.
activity main.xml
<?xml version="1.0"encoding="utf-8"?>
<android.widget.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="com.example.user.square.MainActivity">
<EditText
android:id="@+id/num" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="92dp" android:ems="10"
android:inputType="textPersonName" />
<Button
android:id="@+id/sqrBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/num"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp" android:text="Square" />
<TextView
android:id="@+id/text" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/res"
android:layout_alignStart="@+id/res"
android:layout_below="@+id/sqrBtn"
android:layout_marginTop="39dp" android:textSize="20dp" />
<EditText
android:id="@+id/res" android:layout_width="wrap_content"
8
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/num"
android:layout_alignStart="@+id/num"
android:layout_below="@+id/text" android:ems="10"
android:inputType="textPersonName" />
</android.widget.RelativeLayout>
MainActivity.java
package com.example.user.square;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
9
Output
Result
Program has been executed successfully and output is obtained.
10
3.String Swapper
Aim
Create an android application to make a string swapper.
activity main.xml
<?xml version="1.0"encoding="utf-8"?>
<android.widget.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="com.example.user.swapstrings.MainActivity">
<Button
android:id="@+id/swapBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="170dp" android:text="Swap"
tools:layout_editor_absoluteX="228dp"
tools:layout_editor_absoluteY="423dp" />
<EditText
android:id="@+id/string1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/swapBtn"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="71dp"
android:layout_marginEnd="71dp"
android:layout_marginRight="71dp" android:ems="10"
android:inputType="textPersonName"/>
<EditText
android:id="@+id/string2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/string1"
android:layout_alignStart="@+id/string1"
android:layout_below="@+id/string1"
android:layout_marginTop="27dp" android:ems="10"
11
android:inputType="textPersonName" />
</android.widget.RelativeLayout>
MainActivity.java
package com.example.user.swapstrings;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
});
}
}
12
Output
Result
Program has been executed successfully and output is obtained.
13
4.Simple Calculator
Aim
Create an android application to implement a simple calculator.
activity main.xml
<?xml version="1.0"encoding="utf-8"?>
<android.widget.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="com.example.user.simplecalculator.MainActivity">
<EditText
android:id="@+id/num1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="52dp" android:ems="10"
android:inputType="number" />
<EditText
android:id="@+id/num2" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/num1"
android:layout_alignStart="@+id/num1"
android:layout_below="@+id/num1"
android:layout_marginTop="43dp" android:ems="10"
android:inputType="number"/>
<Button
android:id="@+id/sumBtn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_centerVertical="true"
android:layout_marginLeft="58dp" android:layout_marginStart="58dp"
android:text="@string/sumBtn"/>
<Button
14
android:id="@+id/subBtn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignBottom="@+id/sumBtn"
android:layout_alignParentEnd="true" android:layout_alignParentRight="true"
android:layout_marginEnd="84dp" android:layout_marginRight="84dp"
android:text="@string/subBtn"/>
<Button
android:id="@+id/mulBtn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignLeft="@+id/sumBtn"
android:layout_alignStart="@+id/sumBtn" android:layout_below="@+id/sumBtn"
android:layout_marginTop="77dp" android:text="@string/mulBtn"/>
<Button
android:id="@+id/divBtn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignLeft="@+id/subBtn"
android:layout_alignStart="@+id/subBtn" android:layout_alignTop="@+id/mulBtn"
android:text="@string/divBtn"/>
</android.widget.RelativeLayout>
MainActivity.java
package com.example.user.simplecalculator;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
15
num1 = (TextView) findViewById(R.id.num1); num2 =
(TextView) findViewById(R.id.num2); sum=
(Button)findViewById(R.id.sumBtn); sub=
(Button)findViewById(R.id.subBtn); mul=
(Button)findViewById(R.id.mulBtn); div=
(Button)findViewById(R.id.divBtn);
}
});
16
@Override
public void onClick(View view){
int n1 = Integer.parseInt(num1.getText()+""); int n2 =
Integer.parseInt(num2.getText()+""); res = n1/n2;
Toast.makeText(MainActivity.this,"Answer is : "+res,
Toast.LENGTH_LONG).show();
}
});
}
}
Output
Result
Program has been executed successfully and output is obtained.
17
5.Unit converter
Aim
Crete an android application to converter cm to inches
activity main.xml
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.shlab.converter.MainActivity">
<LinearLayout
android:layout_width="368dp"
android:layout_height="wrap_content"
android:orientation="vertical">
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
18
android:text="height in cm"
tools:layout_editor_absoluteX="36dp"
tools:layout_editor_absoluteY="16dp" />
<TextView
android:id="@+id/result"
android:layout_width="180dp"
android:layout_height="40dp"
android:text="TextView"
tools:layout_editor_absoluteX="50dp"
tools:layout_editor_absoluteY="75dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="converted height"
tools:layout_editor_absoluteX="40dp"
tools:layout_editor_absoluteY="152dp" />
<TextView
android:id="@+id/num"
android:layout_width="205dp"
android:layout_height="39dp"
android:text="TextView"
tools:layout_editor_absoluteX="50dp"
tools:layout_editor_absoluteY="231dp" />
<Button
19
android:id="@+id/conv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="converter"
tools:layout_editor_absoluteX="230dp"
tools:layout_editor_absoluteY="59dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.shlab.converter;
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;
float num1;
double result_num;
EditText e1,e2;
Button con;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1=(EditText)findViewById(R.id.editText);
e2=(EditText)findViewById(R.id.editText2);
20
con=(Button) findViewById(R.id.conv);
con.setOnClickListener(new View.OnClickListener() {
@Override
num1=Float.parseFloat(e1.getText().toString());
e2.setText(String.valueOf(result_num));
});
Output
21
Result
Program has been executed successfully and output is obtained.
22
6.List Layout
Aim
Create an android application to list all semester of BCA course and on selecting a
semester list all subject in that semester on another activity.
activity main.xml
<?xml version="1.0"encoding="utf-8"?>
<android.widget.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="com.example.user.listview.MainActivity">
<TextView
android:id="@+id/s1" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Semester I"
android:textSize="24sp" />
<TextView
android:id="@+id/s2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Semester
II" android:textSize="24sp" />
<TextView
android:id="@+id/s3" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Semester
III" android:textSize="24sp"/>
<TextView
android:id="@+id/s4" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Semester
IV" android:textSize="24sp"/>
<TextView
android:id="@+id/s5" android:layout_width="match_parent"
23
android:layout_height="wrap_content" android:text="Semester
V" android:textSize="24sp"/>
<TextView
android:id="@+id/s6" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Semester
VI" android:textSize="24sp"/>
</android.widget.LinearLayout>
activity semester1.xml
<?xml version="1.0"encoding="utf-8"?>
<android.widget.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="com.example.user.listview.Semester1">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/sub1" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Communication Skills"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Foundation of
Mathematics" android:textSize="18sp"/>
<TextView
android:id="@+id/sub3" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Computer Fundamentals
and Organisation" android:textSize="18sp"/>
<TextView
android:id="@+id/sub4"
24
android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Programming in ’C’" android:textSize="18sp"/>
<TextView
android:id="@+id/sub5" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Introduction to Linux"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Programmingin’C’-Lab"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="IntroductiontoLinux-Lab"
android:textSize="18sp"/>
</LinearLayout>
</android.widget.RelativeLayout>
activity semester2.xml
<?xml version="1.0"encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://
schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.example.user.listview.Semester2">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/sub1" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="CriticalThinking,
Academic,Writingand
Presentation" android:textSize="18sp"/>
<TextView
25
android:id="@+id/sub2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Discrete Mathematics"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp" android:text="Operating
Systen"/>
<TextView
android:id="@+id/sub4"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="OOPs
with C++" android:textSize="18sp"/>
<TextView
android:id="@+id/sub5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DataStructuresusing’C’"
android:textSize="18sp" />
<TextView
android:id="@+id/sub6" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Environmental Science"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub7"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="OOPs
withC++-Lab" android:textSize="18sp"/>
<TextView
android:id="@+id/sub8"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Data
Structuresusing’C’-Lab" android:textSize="18sp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
activity semester3.xml
<?xml version="1.0"encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://
schemas.android.com/apk/res/android"
26
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="com.example.user.listview.Semester3">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/sub1" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Basic Statistics"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Software Engineering"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RDBMS" android:textSize="18sp"/>
<TextView
android:id="@+id/sub4" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Computer Networks"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub5" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Programming in Java"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ProgramminginJava-Lab"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub7" android:layout_width="match_parent"
27
android:layout_height="wrap_content" android:text="RDBMS - Lab"
android:textSize="18sp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
activity semester4.xml
<?xml version="1.0"encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://
schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.example.user.listview.Semester4">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/sub1" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="MobileWeband
ApplicationDevelopment" android:textSize="18sp"/>
<TextView
android:id="@+id/sub2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Introduction to cloud Technology"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub3" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Fundamentals of Data Center"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub4" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="MobileDeviceand
NetworkArchitecture" android:textSize="18sp"/>
<TextView
android:id="@+id/sub5" android:layout_width="match_parent"
android:layout_height="wrap_content"
28
android:text="Basic Android" android:textSize="18sp"/>
<TextView
android:id="@+id/sub6"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Basic
Android - Lab" android:textSize="18sp"/>
<TextView
android:id="@+id/sub7" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Introductionto
cloudTechnology-Lab" android:textSize="18sp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
activity semester5.xml
<?xml version="1.0"encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://
schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.example.user.listview.Semester5">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/sub1" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Principles of Visualization"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub2"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Server
Operating System" android:textSize="18sp"/>
<TextView
android:id="@+id/sub3" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Fundamentals of Storage"
29
android:textSize="18sp"/>
<TextView
android:id="@+id/sub4" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Security
ThreatsandTrends(open)" android:textSize="18sp"/>
<TextView
android:id="@+id/sub5" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Advanced Android"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ServerOperatingSystem-Lab"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AdvancedAndroid-Lab"
android:textSize="18sp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
activity semester6.xml
<?xml version="1.0"encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://
schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.example.user.listview.Semester6">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/sub1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="IntroductiontoMobileUIandUX"
android:textSize="18sp"/>
<TextView
30
android:id="@+id/sub2" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Mobile
EcosystemandSystemModels" android:textSize="18sp"/>
<TextView
android:id="@+id/sub3" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="WebTechnologyandValueaddedservicesin Mobile"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub4" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Mobile Testing"
android:textSize="18sp"/>
<TextView
android:id="@+id/sub5" android:layout_width="match_parent"
android:layout_height="wrap_content" android:text="Project and Viva-Voce"
android:textSize="18sp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.TextView;
publicclassMainActivityextendsAppCompatActivity{ TextView
sem1,sem2,sem3,sem4,sem5,sem6;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sem1=(TextView) findViewById(R.id.s1);
sem2=(TextView) findViewById(R.id.s2);
sem3=(TextView) findViewById(R.id.s3);
sem4=(TextView) findViewById(R.id.s4);
31
sem5=(TextView) findViewById(R.id.s5); sem6=(TextView)
findViewById(R.id.s6);
32
public void onClick(View view){
Intenti=newIntent(MainActivity.this,Semester6.class)
;
startActivity(i);
}
});
}
}
Semester1.java
package com.example.user.listview;
publicclassSemester1extendsAppCompatActivity{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_semester1);
}
}
Semester2.java
package com.example.user.listview;
publicclassSemester2extendsAppCompatActivity{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_semester2);
}
}
Semester3.java
package com.example.user.listview;
publicclassSemester3extendsAppCompatActivity{ @Override
protected void onCreate(Bundle savedInstanceState) {
33
super.onCreate(savedInstanceState); setContentView(R.layout.activity_semester3);
}
}
Semester4.java
package com.example.user.listview;
publicclassSemester4extendsAppCompatActivity{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_semester4);
}
}
Semester5.java
package com.example.user.listview;
publicclassSemester5extendsAppCompatActivity{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_semester5);
}
}
Semester6.java
package com.example.user.listview;
publicclassSemester6extendsAppCompatActivity{ @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_semester6);
}
}
34
Output
Result
Program has been executed successfully and output is obtained.
35
7.Intent
Aim
Create an android application to illustrate the working of intent.
activity main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:id="@+id/mystring"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.shlab.myintent;
import android.content.Intent;
36
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
b=(Button)findViewById(R.id.next);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text=(EditText) findViewById(R.id.getstring);
msg=text.getText().toString();
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
intent.putExtra("message",msg);
startActivity(intent);
}
});
}
}
AndroidManifestFile.XML
?xml version="1.0" encoding="utf-8"?>
37
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.shlab.myintent">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
MainActivity2.java
package com.example.shlab.myintent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
Result
Program has been executed successfully and output is obtained.
39
8.SHARED PREFERENCE
Aim
create an android application to demonstrate the working of shared preference.
activitymain.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.shlab.shared.MainActivity">
<LinearLayout
android:layout_width="368dp"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView"
android:layout_width="109dp"
android:layout_height="46dp"
android:text="Username"
/>
<EditText
android:id="@+id/usernameInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
40
/>
<TextView
android:id="@+id/textView2"
android:layout_width="111dp"
android:layout_height="32dp"
android:text="Password"
/>
<EditText
android:id="@+id/passwordInput"
android:layout_width="211dp"
android:layout_height="41dp"
android:ems="10"
android:inputType="textPersonName"
/>
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Info"
/>
<Button
android:id="@+id/display"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display Info"
/>
41
<TextView
android:id="@+id/buckysText"
android:layout_width="206dp"
android:layout_height="75dp"
android:text="d"
/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.shlab.shared;
import android.content.Context;
import android.content.SharedPreferences;
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;
Toast.makeText(getApplicationContext(),"Saved!",Toast.LENGTH_LONG).show();
}
});
disp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences
sharedPref=getSharedPreferences("userInfo",Context.MODE_PRIVATE);
String name=sharedPref.getString("username"," ");
String pw=sharedPref.getString("password"," ");
buckysText.setText(name+" "+pw);
}
});
}
43
}
Output
Saved output
44
Display output
Result
Program has been executed successfully and output is obtained.
45
9.File
Aim
Create an android application to save a file on internal storage.
activity main.xml
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:orientation="vertical"
tools:layout_editor_absoluteX="-9dp"
tools:layout_editor_absoluteY="0dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
46
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="51dp"
tools:layout_editor_absoluteY="47dp" />
<Button
android:id="@+id/read"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="read"
tools:layout_editor_absoluteX="51dp"
tools:layout_editor_absoluteY="154dp" />
<Button
android:id="@+id/write"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="write"
tools:layout_editor_absoluteX="212dp"
tools:layout_editor_absoluteY="154dp" />
<TextView
android:id="@+id/textView"
android:layout_width="237dp"
android:layout_height="75dp"
android:text="TextView"
tools:layout_editor_absoluteX="74dp"
47
tools:layout_editor_absoluteY="278dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.shlab.file;
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;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@Override
protected void onCreate(Bundle savedInstanceState) {
48
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = (EditText) findViewById(R.id.editText);
textView = (TextView) findViewById(R.id.textView);
bt1 = (Button) findViewById(R.id.read);
bt2 = (Button) findViewById(R.id.write);
bt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
filecontents = editText.getText().toString();
try {
FileOutputStream fileOutputStream = openFileOutput(filename,
MODE_PRIVATE);
fileOutputStream.write(filecontents.getBytes());
fileOutputStream.close();
File dir = new File(getFilesDir(), filename);
Toast.makeText(getApplicationContext(), "file save at" + dir,
Toast.LENGTH_LONG).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
bt2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String text = "";
try {
49
FileInputStream fin = openFileInput(filename);
int sizef;
sizef = fin.available();
byte[] buffer = new byte[sizef];
fin.read(buffer);
fin.close();
text = new String(buffer);
textView.setText(text);
} catch (IOException e)
{
e.printStackTrace();
}
}
});
50
Output
read
write
51
Result
Program has been executed successfully and output is obtained.
52
10.Database
Aim
Create an android application to demonstrate the working a database
activity main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.shlab.database.MainActivity">
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:orientation="vertical"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="184dp"
53
android:layout_height="31dp"
android:text="TextView"
tools:layout_editor_absoluteX="84dp"
tools:layout_editor_absoluteY="29dp" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.shlab.database;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.util.concurrent.Callable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView=(TextView)findViewById(R.id.textView);
SQLiteDatabase database=openOrCreateDatabase("ramsdb.db",MODE_PRIVATE,null);
database.execSQL("create table if not exists sampletable(name text,location text)");
database.execSQL("insert into sampletable values ('ram','hydrabad')");
Cursor cursor=database.rawQuery("select*from sampletable",null);
cursor.moveToFirst();
String name=cursor.getString(0);
54
String location=cursor.getString(1);
textView.setText(name+"\n"+location);
database.close();
}
};
OUTPUT
Result
Program has been executed successfully and output is obtained.
55
11.Contacts Application
Aim
Create an application to create custom list view to show name, phone number of some persons
along with a call button and the app should make call to particular person when the call button
is tapped.
activity main.xml
<?xml version="1.0"encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://
schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="demo.workshop.contactapp.MainActivity">
<ListView android:id="@+id/datalist"
android:layout_width="fill_parent"
android:layout_height="448dp"
android:layout_marginTop="40dp" />s
</android.support.constraint.ConstraintLayout>
activity custom list.xml
<?xml version="1.0"encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/ android"
android:layout_width="match_parent" android:layout_height="match_parent">
<FrameLayout android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_below="@+id/signup"
android:layout_alignParentLeft="true">
<TextView
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25dp" android:text="TextView"
android:textColor="#000000"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="false"
56
android:layout_alignParentRight="true" android:layout_gravity="top|left"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:text="Small Text"
android:id="@+id/Number" android:layout_alignBottom="@+id/signup"
android:layout_alignParentRight="true"
<Button
android:layout_width="60dp" android:layout_height="70dp"
android:id="@+id/signup" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" android:layout_gravity="right|bottom"
android:background="@drawable/call"/>
</FrameLayout>
</RelativeLayout>
MainActivity.java
android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import
android.widget.ListView;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mthis = this;
lv = (ListView) findViewById(R.id.datalist); lv.setAdapter(newCustomList(mthis));
57
}
}
CustomList.java
package demo.workshop.contactapp;
Context context;
public String Names[]={"Anand","Abin Augustine"}; public String
Numbers[]={"9961529186","7736999367"}; privatestaticLayoutInflater
inflater=null;
@Override
publicintgetCount(){ return
Names.length;
}
@Override
publicObjectgetItem(intposition){ return position;
}
@Override
publiclonggetItemId(intposition){ return position;
}
120
TextViewtv;
TextViewnum;
Button callBtn;
@Override
publicViewgetView(finalintposition,ViewconvertView,ViewGroup parent) {
holder.callBtn=(Button)rowView.findViewById(R.id.signup);
holder.callBtn.setOnClickListener(new View.OnClickListener() {
121
Output
Result
Program has been executed successfully and output is obtained.
122
12.Notification
Aim
Crete an android application to receive notification in your notification drawer.
activitymain.xml
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="notify"
/>
123
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.shlab.notification;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button not,next;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
not=(Button)findViewById(R.id.button);
next=(Button)findViewById(R.id.button2);
not.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
124
PendingIntent Pintent = PendingIntent.getActivity(getApplicationContext(), (int)
System.currentTimeMillis(), intent, 0);
NotificationCompat.Builder mBuilder =
(NotificationCompat.Builder) new
NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.marsh)
.setContentTitle("My notification")
.setContentText("Hello World!");
notificationManager.notify(001, mBuilder.build());
}
});
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), Notification.class);
startActivity(i);
}
});
}
}
AndroidmanifestFile.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
125
package="com.example.shlab.notification">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
126
OUTPUT
Result
Program has been executed successfully and output is obtained.
127
128