Mad Lab Ec354r19 Manual 2021-2022
Mad Lab Ec354r19 Manual 2021-2022
Mad Lab Ec354r19 Manual 2021-2022
LABORATORY MANUAL
PREPARED BY
MRS.B.MAHA LAKSHMI
ASSISTANT PROFESSOR
DEPARTMENT OF E.C.E
DEPARTMENT OF
ELECTRONICS AND COMMUNICATION ENGINEERING
(A.Y:2021-22)
Vision:-
Mission:-
PEO2: Competence in using modern electronic tools in hardware and software co-
design for networking and communication applications.
PSO2: Ability to design and develop computing systems using concepts of mathematics,
electronics engineering and other related disciplines
PSO3: Apply the engineering knowledge to asses and resolve societal, environmental, health
safety and cultural issues with professional ethics
SYLLABUS
EC354R19 MOBILE APPLICATION DEVELOPMENT LABORATORY L T P C
0 0 3 1.5
OBJECTIVES:
To understand the components and structure of mobile application development
frameworks for Android and windows OS based mobiles.
To understand how to work with various mobile application development frameworks.
To learn the basic and important design concepts and issues of development of mobile
applications.
To understand the capabilities and limitations of mobile devices.
LIST OF EXPERIMENTS
OUTCOMES:
REFERENCES:
LIST OF EXPERIMENTS
C354.2 Make use of database concepts for data related mobile applications Apply
C354.3 Develop mobile applications using Internal & External Storage, SMS Apply
Notification, Multithreading, and GPS.
C354.4 Model the mobile application using RSS Feed, Alert upon receiving a Apply
message and send an E-Mail
C354.5 Develop Mobile App for simple real time needs Apply
2 C354.2
l l l 1 - 1 - 2 - - - 1 - - 1
3 C354.3
l l l 1 - 1 - 2 - - - 1 - - 1
4 C354.4 1
l l l 1 - 1 - 2 - - - - - 1
5 C354.5
2 2 2 2 2 2 1 2 2 - - 2 1 - 2
INDEX
INTRODUCTION TO ANDROID OS
INTRODUCTION :
Android is a Linux based operating system it is designed primarily for touch screen
mobile devices such as smart phones and tablet computers. The android is a powerful
operating system and it supports large number of applications in Smartphones. These
applications are more comfortable and advanced for the users. The hardware that supports
android software is based on ARM architecture platform.
The android is an open source operating system. The android has got millions of apps
available that can help you managing your life one or other way and it is available low cost in
market at that reasons android is very popular.
The android development supports with the full java programming language. Even
other packages that are API and JSE are not supported. The first version 1.0 of android
development kit (SDK) was released in 2008 .
ANDROID ARCHITECTURE :
The android is an operating system and is a stack of software components which is
divided into five sections and four main layers that is
Linux kernel
Libraries
Android runtime
LINUX KERNEL :
The android uses the powerful Linux kernel and it supports wide range of hardware
drivers. The kernel is the heart of the operating system that manages input and output
requests from software. This provides basic system functionalities like process management,
memory management; device management like camera, keypad, and display etc., the kernel
handles all the things. The Linux is really good at networking and it is not necessary to
interface it to the peripheral hardware. The kernel itself does not interact directly with the
user but rather interacts with the shell and other programs as well as with the hardware
devices on the system.
LIBRARIES :
On top of a Linux kennel there is a set of libraries including open source web browser
such as webkit, library libc. These libraries are used to play and record audio and video. The
SQLite is a data base which is useful for storage and sharing of application data. The SSL
libraries are responsible for internet security etc.
ANDROID RUNTIME :
The android runtime provides a key component called Dalvik Virtual Machine
which is a kind of java virtual machine. It is specially designed and optimized for android.
The Dalvik VM is the process virtual machine in the android operating system. It is software
that runs apps on android devices.
The Dalvik VM makes use of Linux core features like memory management and
multithreading which is in a java language. The Dalvik VM enables every android application
to run its own process. The Dalvik VM executes the files in the .dex format.
The application frame work layer provides many higher level services to applications
such as windows manager, view system, package manager, resource manager etc. The application
developers are allowed to make use of these services in their application.
The android applications are at the top layer and we will write our application and install on
this layer. Example of such applications is contacts, books, browsers, services etc.
FEATURES:
ANDROID VERSIONS:
FEATURES:
PROCEDURE:
Open Android Stdio and then click on File -> New -> New project.
Then select the Minimum SDK as shown below and click Next
AIM :
To develop a Simple Android Application that uses GUI components, Font and Colours.
PROCEDURE :
Step 1: Create an android project using android studio.
Step 2: Design
2.1. Open the actual Project folder (app) in Android Studio IDE.
2.2. Click res directory -> layout -> activity_main.xml -> Design.
2.3. Insert the GUI components to Design view in activity_main.xml.
2.4. Enter the id for each component.
Step 3: Open res directory -> layout -> activity_main.xml and add the code.
Step 4: Open java -> MainActivity.java and add the code.
Step 5: Run the project and the output will be displayed in Emulator.
LAYOUT DESIGN:
XML File :-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
JAVA File :-
package com.example.exno1;
import android.graphics.Color;
import android.os.Bundle;
//import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
case 1: t.setTextColor(Color.RED);
break;
case 2: t.setTextColor(Color.GREEN);
break;
case 3: t.setTextColor(Color.BLUE);
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;
}
});
}
}
OUTPUT:-
AIM :
To develop a Simple Android Application that uses Layout Managers and Event Listeners.
PROCEDURE:
LAYOUT DESIGN:
XML FILE:-
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="ADDITION"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTER NO 1" >
</TextView>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:id="@+id/edittext1"
android:inputType="number">
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTER NO 2" >
</TextView>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:id="@+id/edittext2"
android:inputType="number">
</EditText>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout3" >
<Button
android:layout_width="wrap_content"
android:id="@+id/button1"
android:layout_height="wrap_content"
android:text="Addition"
android:layout_weight="0.50" />
<Button
android:layout_width="wrap_content"
android:id="@+id/button3"
android:layout_height="wrap_content"
android:text="subtraction"
android:layout_weight="0.50" />
<Button
android:layout_width="wrap_content"
android:id="@+id/button2"
android:layout_height="wrap_content"
android:text="CLEAR"
android:layout_weight="0.50" />
</LinearLayout>
<View
android:layout_height="2px"
android:layout_width="fill_parent"
android:layout_below="@+id/linearLayout4"
android:background="#DDFFDD"/>
</RelativeLayout>
JAVA File :-
//package layout.ne;
package com.example.exno2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
//setContentView(R.layout.main);
setContentView(R.layout.activity_main);
Button add = (Button)
findViewById(R.id.button1);
add.setOnClickListener(new OnClickListener()
{ public void onClick(View v) {
try
{
txtData1 = (EditText) findViewById(R.id.edittext1);
txtData2 = (EditText) findViewById(R.id.edittext2);
num1 = Float.parseFloat(txtData1.getText().toString()); num2 =
Float.parseFloat(txtData2.getText().toString());
result1=num1+num2;
Toast.makeText(getBaseContext(),"ANSWER:"+result1,Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
Button sub = (Button) findViewById(R.id.button3);
sub.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try
{
txtData1 = (EditText) findViewById(R.id.edittext1);
txtData2 = (EditText) findViewById(R.id.edittext2);
num1 = Float.parseFloat(txtData1.getText().toString());
num2 = Float.parseFloat(txtData2.getText().toString());
result2=num1-num2;
Toast.makeText(getBaseContext(),"ANSWER:"+result2,Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
txtData2.setText("");
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
}
}
OUTPUT:-
PROCEDURE :-
LAYOUT DESIGN:-
XML FILE:-
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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"
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"
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" />
<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>
JAVA FILE:-
package com.example.prgm3;
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;
Rollno=(EditText)findViewById(R.id.Rollno);
Name=(EditText)findViewById(R.id.Name);
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);
{
showMessage("Error", "Please enter all values");
return;
}
db.execSQL("INSERT INTO student VALUES('"+Rollno.getText()
+"','"+Name.getText()+
"','"+Marks.getText()+"');");
showMessage("Success", "Record added");
clearText();
}
// Deleting a record from the Student table
if(view==Delete)
{
// Checking for empty roll number
if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
rollno='"+Rollno.getText()+"'", null);
if(c.moveToFirst())
{
db.execSQL("DELETE FROM student WHERE rollno='"+Rollno.getText()
+"'");
showMessage("Success", "Record Deleted");
}
else
{
showMessage("Error", "Invalid Rollno");
}
clearText();
}
// Updating a record in the Student table
if(view==Update)
{
// Checking for empty roll number
if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
rollno='"+Rollno.getText()+"'", null);
if(c.moveToFirst()) {
db.execSQL("UPDATE student SET name='" + Name.getText() + "',marks='"
+ Marks.getText() +
"' WHERE rollno='"+Rollno.getText()+"'");
showMessage("Success", "Record Modified");
}
else {
showMessage("Error", "Invalid Rollno");
}
clearText();
}
// Display a record from the Student table
if(view==View)
{
// Checking for empty roll number
if(Rollno.getText().toString().trim().length()==0)
{
showMessage("Error", "Please enter Rollno");
return;
}
Cursor c=db.rawQuery("SELECT * FROM student WHERE
rollno='"+Rollno.getText()+"'", null);
if(c.moveToFirst())
{
Name.setText(c.getString(1));
Marks.setText(c.getString(2));
}
else
{
showMessage("Error", "Invalid Rollno");
clearText();
}
}
// Displaying all the records
if(view==ViewAll)
{
Cursor c=db.rawQuery("SELECT * FROM student", null);
if(c.getCount()==0)
{
showMessage("Error", "No records found");
return;
}
StringBuffer buffer=new StringBuffer();
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");
}
showMessage("Student Details", buffer.toString());
}
}
public void showMessage(String title,String message)
{
Builder builder=new Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}
public void clearText()
{
Rollno.setText("");
Name.setText("");
Marks.setText("");
Rollno.requestFocus();
}
}
OUTPUT:-
AIM :
PROCEDURE :
LAYOUT DESIGN:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:text="Notify"
android:textAllCaps="false"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:id="@+id/btnNotify"
android:textColor="@android:color/white"
android:textSize="18dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
<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.spaceo.notificationalertdemo.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>
package com.example.notimgr;
//package com.spaceo.notificationalertdemo
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import kotlinx.android.synthetic.main.activity_main.*;
public class MainActivity extends AppCompatActivity
{
private val NOTIFY_ME_ID = 1337;
private val NOTIFICATION_CHANNEL_ID = "My Channel";
setContentView(R.layout.activity_main);
//PendingIntent Create
notificationManager.notify(R.drawable.notification, builder.build())
}
}
package com.example.notimgr;
//package com.spaceo.notificationalertdemo
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
class NotifyMessage : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_notifymessage)
}
}
SAMPLE OUTPUT:-
AIM:-
PROCEDURE:-
main.xml file:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/show_Location
"
android:layout_width="wrap_cont
ent"
android:layout_height="wrap_cont
ent
android:text="Show_Location"
android:layout_centerVertical="tr
ue"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
mainactivity.java file :-
//import android.R;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Butto
n; import
android.widget.Toast
;
public class GPSlocationActivity extends Activity {
/** Called when the activity is first created. */
Button btnShowLocation;
GPStrace gps;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnShowLocation=(Button)findViewById(R.id.show_Location);
btnShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
}
GPStrace.java file :-
Package gps.location;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import
android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import
android.location.LocationListener
; import
android.location.LocationManage
r; import android.os.Bundle;
import android.os.IBinder; import
android.provider.Settings;
public class GPStrace extends Service implements
LocationListener{ private final Context context; boolean
isGPSEnabled=false; boolean canGetLocation=false; boolean
isNetworkEnabled=false;
Location
location; double
latitude; double
longtitude;
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES=10;
private static final long MIN_TIME_BW_UPDATES=1000*60*1;
protected LocationManager locationManager;
public GPStrace(Context context)
{
this.context=conte
xt;
getLocation();
public Location getLocation()
{
try{
locationManager=(LocationManager) context.getSystemService(LOCATION_SERVICE);
isGPSEnabled=locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
;
isNetworkEnabled=locationManager.isProviderEnabled(LocationManager.NETWORK_PR
OVI DER);
if(!isGPSEnabled && !isNetworkEnabled){
}else{
this.canGetLocation=true;
if(isNetworkEnabled){
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,this);
}
if(locationManager!=null){
location=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVI
DER)
;
if(location !=null){
latitude=location.getLatitude();
longtitude=location.getLongitude();
}
}
}
if(isGPSEnabled){
if(location==null){
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MIN_TIM
E_B
W_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if(locationManager!=null){
location=locationManager.getLastKnownLocation(LocationManager.GPS_PROV
IDER); if(location!=null){
latitude=location.getLatitude();
longtitude=location.getLongitude();
}
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return location;
}
public void stopUsingGPS(){
if(locationManager!=null){
locationManager.removeUpdates(GPStrace.this);
} } public double
getLatitude(){
if(location!=null){
latitude=location.getLatitude();
}
return latitude;
}
public double getLongtiude(){
if(location!=null){
longtitude=location.getLatitude();
}
return longtitude;
}
OUTPUT:-
AIM:
To Implement an application that for basic Calculator.
PROCEDURE:-
Step 1: Firstly get the android studio downloaded in your system, then open it.
Step 2: Create a new project and name it Calculator.
Step 3: Open res -> layout -> activity_main.xml (or) main.xml. Here we are going to create
the application interface like add layouts, Button , TextView and EditText.
i of Step 3 – Create a Linearlayout vertical, add a textview followed by two textfields
Number(decimal) for writing numbers in it. Starting code of activity_main.xml
ii of Step 3 – Then before closing the above layout define another layout as Linear layout
horizontal, add five button ( +, -, *, / and Clear) define their properties like id , width, height
etc. in it and close the linear layout
iii of Step 3 – Further in continuation with previous linear layout add a text view, text
field(Number) for displaying result which makes the interface complete.
Step 4: Open src -> package -> MainActivity.java. The interface part of the application is
over, let’s focus on adding functionality to the application. This calculator app basically
perform five operations i.e addition, subtraction, multiplication, division and reset. So for that
we need to define these operation over button click. For that we use setOnClickListener()
function. parseDouble() is used to convert String value to double. By default the value is
String and we need to convert it into Double to perform operation over it.
If person doesn’t enter the value and directly click on the any button then a Toast message
will appear on the screen telling user to enter the required numbers.
MAIN XML FILE:-
<?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.a84.calculator.MainActivity">
<RelativeLayout
android:layout_width="400dp"
android:layout_height="495dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/edText1"
android:layout_marginTop="60dp"
android:onClick="PressOne"
android:text="1"
android:textSize="18sp" />
<Button
android:id="@+id/btn_0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_8"
android:layout_toEndOf="@+id/btn_7"
android:layout_toRightOf="@+id/btn_7"
android:text="0"
android:textSize="18sp" />
<Button
android:id="@+id/btn_9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_6"
android:layout_toEndOf="@+id/btn_5"
android:layout_toRightOf="@+id/btn_5"
android:text="9"
android:textSize="18sp" />
<Button
android:id="@+id/btn_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_5"
android:layout_toEndOf="@+id/btn_7"
android:layout_toRightOf="@+id/btn_7"
android:text="8"
android:textSize="18sp" />
<Button
android:id="@+id/btn_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_4"
android:layout_alignStart="@+id/btn_4"
android:layout_below="@+id/btn_4"
android:text="7"
android:textSize="18sp" />
<Button
android:id="@+id/btn_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_5"
android:layout_alignBottom="@+id/btn_5"
android:layout_toEndOf="@+id/btn_5"
android:layout_toRightOf="@+id/btn_5"
android:text="6"
android:textSize="18sp" />
<Button
android:id="@+id/btn_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_2"
android:layout_toEndOf="@+id/btn_4"
android:layout_toRightOf="@+id/btn_4"
android:text="5"
android:textSize="18sp" />
<Button
android:id="@+id/btn_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_1"
android:layout_alignStart="@+id/btn_1"
android:layout_below="@+id/btn_1"
android:text="4"
android:textSize="18sp" />
<Button
android:id="@+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_2"
android:layout_alignBottom="@+id/btn_2"
android:layout_toEndOf="@+id/btn_2"
android:layout_toRightOf="@+id/btn_2"
android:text="3"
android:textSize="18sp" />
<Button
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btn_1"
android:layout_alignBottom="@+id/btn_1"
android:layout_toEndOf="@+id/btn_1"
android:layout_toRightOf="@+id/btn_1"
android:text="2"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btn_6"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:backgroundTint="@android:color/darker_gray"
android:text="+"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Add"
android:layout_alignStart="@+id/btn_Add"
android:layout_below="@+id/btn_Add"
android:backgroundTint="@android:color/darker_gray"
android:text="-"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Sub"
android:layout_alignStart="@+id/btn_Sub"
android:layout_below="@+id/btn_6"
android:backgroundTint="@android:color/darker_gray"
android:text="*"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<Button
android:id="@+id/btn_Div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btn_Mul"
android:layout_alignStart="@+id/btn_Mul"
android:layout_below="@+id/btn_9"
android:backgroundTint="@android:color/darker_gray"
android:text="/"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<EditText
android:id="@+id/edText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="80dp"
android:ems="10"
android:inputType="textPersonName"
android:textAlignment="textEnd"
android:textSize="24sp" />
<Button
android:id="@+id/btn_calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_0"
android:layout_toEndOf="@+id/btn_0"
android:layout_toRightOf="@+id/btn_0"
android:backgroundTint="@android:color/holo_green_light"
android:text="="
android:textColor="@android:color/background_light"
android:textSize="18sp" />
<Button
android:id="@+id/btn_dec"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_7"
android:layout_toLeftOf="@+id/btn_8"
android:layout_toStartOf="@+id/btn_8"
android:text="."
android:textSize="18sp" />
<Button
android:id="@+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/btn_Div"
android:backgroundTint="@android:color/holo_blue_dark"
android:text="clear"
android:textColor="@android:color/background_light"
android:textSize="18sp" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
Java file :-
package com.example.p4;
//import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.Activity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"0");
}
});
btn_1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"1");
}
});
btn_2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"2");
}
});
btn_3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"3");
}
});
btn_4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"4");
}
});
btn_5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"5");
}
});
btn_6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"6");
}
});
btn_7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"7");
}
});
btn_8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"8");
}
});
btn_9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+"9");
}
});
btn_dec.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText(ed1.getText()+".");
}
});
btn_Add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ed1 == null){
ed1.setText("");
}else {
Value1 = Float.parseFloat(ed1.getText() + "");
mAddition = true;
ed1.setText(null);
}
}
});
btn_Sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Float.parseFloat(ed1.getText() + "");
mSubtract = true ;
ed1.setText(null);
}
});
btn_Mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Float.parseFloat(ed1.getText() + "");
mMultiplication = true ;
ed1.setText(null);
}
});
btn_Div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value1 = Float.parseFloat(ed1.getText()+"");
mDivision = true ;
ed1.setText(null);
}
});
btn_calc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Value2 = Float.parseFloat(ed1.getText() + "");
if (mAddition == true){
if (mSubtract == true){
ed1.setText(Value1 - Value2 +"");
mSubtract=false;
}
if (mMultiplication == true){
ed1.setText(Value1 * Value2 + "");
mMultiplication=false;
}
if (mDivision == true){
ed1.setText(Value1 / Value2+"");
mDivision=false;
}
}
});
btn_clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ed1.setText("");
}
});
}
OUTPUT:-
AIM:-
T0 Implement an application that creates an alert upon receiving a message
PROCEDURE:-
1) Open eclipse or android studio and select new android project
2) Give project name and select next
3) Choose the android version. Choose the lowest android version(Android 2.2) and select next
4) Enter the package name. package name must be two word separated by comma and click
finish
5) Go to package explorer in the left hand side. select our project.
6) Go to res folder and select layout. Double click the main.xml file. Add the code given.
7) Now select mainactivity.java file and type the following code. In my coding man activity name is
Alert1Activity.
8) Now go to main.xml and right click .select run as option and select run configuration
android:layout_height="2px"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:background="#DDFFDD"/>
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="1.CAPTIAL OF INDIA"
android:layout_span="4"
android:padding="18dip"
android:textColor="#ffffff"/>
</TableRow><TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer1A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="CHENNAI" />
<RadioButton
android:id="@+id/answer1B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="NEW DELHI" />
<RadioButton
android:id="@+id/answer1C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="MUMBAI" />
<RadioButton
android:id="@+id/answer1D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="HYDERBAD" />
</RadioGroup>
</TableRow><TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp" android:text="2. CAPTIAL OF
RUSSIA?" android:layout_span="4"
android:padding="18dip" android:textColor="#ffffff"/>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<RadioGroup
android:id="@+id/answer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4" >
<RadioButton
android:id="@+id/answer2A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="WARSAW " />
<RadioButton
android:id="@+id/answer2B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="BERLIN" />
<RadioButton
android:id="@+id/answer2C"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="MASCOW " />
<RadioButton
android:id="@+id/answer2D"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="CANEBRA " />
</RadioGroup>
</TableRow><TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<Button
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Submit" />
</TableRow>
</TableLayout></ScrollView>
OUTPUT:-
AIM :-
LAYOUT DESIGN:-
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Adding permissions in Manifest for the Android Application:
<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" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
So now the Permissions are added in the Manifest.
Java Coding for the Android Application:
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;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
new MyAsyncTask().execute();
}
insideItem = true;
}
else if (xpp.getName().equalsIgnoreCase("title"))
{
if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
}
else if (xpp.getName().equalsIgnoreCase("link"))
{
if (insideItem)
links.add(xpp.nextText()); //extract the link of article
}
}
else if(eventType==XmlPullParser.END_TAG && xpp.getName().
equalsIgnoreCase("item"))
{
insideItem=false;
}
eventType = xpp.next(); //move to next element
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (XmlPullParserException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
protected void onPostExecute(ArrayAdapter adapter)
adapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1,
headlines);
setListAdapter(adapter);
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
Uri uri = Uri.parse((links.get(position)).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
OUTPUT:-
AIM:-
To develop an Android Application to send an Email.
PROCEDURE :-
LAYOUT DESIGN:-
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
/>
<TextView
android:id="@+id/textView3"
android:textColor="#0F9D58"
android:text="Email Body:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
/>
android:id="@+id/button"
android:text="Send email!!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText3"
android:layout_below="@+id/editText3"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
/>
</RelativeLayout>
package com.geeksforgeeks.phonecall;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.widget.EditText;
import android.view.View;
import android.view.View.OnClickListener;
import android.net.Uri;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
// define objects for edit text and button
Button button;
EditText sendto, subject, body;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Getting instance of edittext and button
sendto = findViewById(R.id.editText1);
subject = findViewById(R.id.editText2);
body = findViewById(R.id.editText3);
button = findViewById(R.id.button);
OUTPUT:-
AIM:-
To write a mobile application that creates alarm clock
PROCEDURE:-
1. Android Manifest--AndroidManifest.xml
We need to give uses-permission for WAKE_LOCK, other than that the AndroidManifest.xml
is pretty standard one. Just need to include the service and receiver.
2. Android Activity--activity_my.xml
The Android Activity is designed to be simple. We have a Time Picker component followed
by a Toggle Button. That’s it. Choose the time to set the alarm and toggle the switch to on.
The alarm will work.
3. Alarm Receiver--AlarmReceiver.java
this is the one that receives the alarm trigger on set time. From here we initiate different
actions to notify the user as per our choice. I have given three type of notifications, first show
a message to user in the activity UI, second play the alarm ringtone and third send an Android
notification message. So this is the place to add enhancement for different types of user
notifications.
4. Alarm Notification Message --AlarmService.java
The receiver will start the following Intent Service to send a standard notification to the user.
AndroidManifest.xml:-
activity_my.xml FILE:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MyActivity">
<TimePicker
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:id="@+id/alarmTimePicker" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Alarm
On/Off" android:id="@+id/alarmToggle"
android:layout_centerHorizontal="true"
android:layout_below="@+id/alarmTimePicker"
android:onClick="onToggleClicked" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="" android:id="@+id/alarmText"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:layout_below="@+id/alarmToggle" />
</RelativeLayout>
AlarmReceiver.java FILE:-
package com.javapapers.androidalarmclock;
import android.app.Activity; import
android.app.AlarmManager; import
android.app.PendingIntent; import
android.content.Intent; import
android.os.Bundle; import
android.util.Log; import
android.view.View; import
android.widget.TextView; import
android.widget.TimePicker; import
android.widget.ToggleButton;
import java.util.Calendar; public
class AlarmActivity extends Activity
{
AlarmManager alarmManager; private
PendingIntent pendingIntent; private
package com.javapapers.androidalarmclock;
import android.app.Activity; import
android.content.ComponentName; import
android.content.Context; import
android.content.Intent; import
android.media.Ringtone; import
android.media.RingtoneManager; import
android.net.Uri;
import android.support.v4.content.WakefulBroadcastReceiver; public class
AlarmReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
//this will update the UI with message AlarmActivity inst =
AlarmActivity.instance(); inst.setAlarmText("Alarm! Wake up!
Wake up!");
package com.javapapers.androidalarmclock;
import android.app.IntentService; import
android.app.NotificationManager; import
android.app.PendingIntent; import
android.content.Context; import
android.content.Intent;
import android.support.v4.app.NotificationCompat; import
android.util.Log;
public class AlarmService extends IntentService { private
NotificationManager alarmNotificationManager;
public AlarmService() {
super("AlarmService"); }
@Override
public void onHandleIntent(Intent intent) { sendNotification("Wake Up! Wake
Up!");
}
private void sendNotification(String msg) {
Log.d("AlarmService", "Preparing to send notification...: " + msg);
alarmNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this,
AlarmActivity.class), 0);
NotificationCompat.Builder alamNotificationBuilder = new
NotificationCompat.Builder(this).setContentTitle("Alarm").setSmallIcon(R.drawable.ic_laun
cher)
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg);
alamNotificationBuilder.setContentIntent(contentIntent);
alarmNotificationManager.notify(1, alamNotificationBuilder.build());
Log.d("AlarmService", "Notification sent."); }
}
OUTPUT:-