Mobile Communication 1701109

Download as pdf or txt
Download as pdf or txt
You are on page 1of 115

1701109

EX NO 1
STUDY ON ANDROID AND ANDROID STUDIO
DATE:
6.12.19

AIM:
To study about Android and Android Studio in detail.

ANDROID:

Introduction:
Android is a mobile operating system based on a modified version of the Linux kernel and
other open source software, designed primarily for touchscreen mobile devices such
as smartphones and tablets. Android is developed by a consortium of developers known as
the Open Handset Alliance, with the main contributor and commercial marketer being Google.
Initially developed by Android Inc., which Google bought in 2005, Android was unveiled
in 2007, with the first commercial Android device launched in September 2008. The current
stable version is Android 10, released on September 3, 2019. The core Android source code is
known as Android Open Source Project (AOSP), which is primarily licensed under the Apache
License. This has allowed variants of Android to be developed on a range of other electronics,
such as game consoles, digital cameras, PCs,Android TV for televisions and Android Wear
OS for wearables.

Features of Android:
Android is a powerful operating system competing with Apple 4GS and supports great
features. Few of them are listed below
1) Beautiful UI
Android OS basic screen provides a beautiful and intuitive user interface.
2) Connectivity
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC and
WiMAX.
3) Storage
SQLite, a lightweight relational database, is used for data storage purposes.
4) Mediasupport
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3, MIDI,
OggVorbis, WAV, JPEG, PNG, GIF, and BMP.
5) Messaging
SMS and MMS
6) Webbrowser
Based on the open-source WebKit layout engine, coupled with Chrome's V8 JavaScript
engine supporting HTML5 and CSS3.
7) Multi-touch
Android has native support for multi-touch which was initially made available in
handsets such as the HTC Hero.
8) Multi-tasking
User can jump from one task to another and same time various application can run
simultaneously.
1701109

9) Resizablewidgets
Widgets are resizable, so users can expand them to show more content or shrink them
to save space.
10) Multi-Language
Supports single direction and bi-directional text.
11) GCM
Google Cloud Messaging (GCM) is a service that lets developers send short message
data to theirusers on Android devices, without needing a proprietary sync solution.
12) Wi-FiDirect
A technology that lets apps discover and pair directly, over a high-bandwidth peer-to-
peer connection.
13) AndroidBeam
A popular NFC-based technology that lets users instantly share, just by touching two
NFC-enabled phones together.

Architecture:
Android operating system is a stack of software components which is roughly divided into
five sections and four main layers as shown below in the architecture diagram.

Applications

Application Framework
Android
Libraries Runtime

Linux Kernel

1) Linux kernel
At the bottom of the layers is Linux. This provides a level of abstraction between the
device hardware and it contains all the essential hardware drivers.

2) Libraries
On top of Linux kernel there is a set of libraries such as Surface Manager, Media
Framework,WebKit (open-source Web browser engine), Libc (a well-known library),
SQLite (database), SSL libraries (for Internet security), etc.
Android Libraries encompass Java-based libraries specific to Android development.
Examples of libraries in this category include the application framework libraries in
addition to those that facilitate user interface building, graphics drawing and database
access.
Eg: android.app, android.content, android.database, etc

3) Android Runtime
This section provides a key component called Dalvik Virtual Machine which is a kind of
Java Virtual Machine specially designed and optimized for Android.
It makes use of Linux core features like memory management and multi-threading,
which is intrinsic in the Java language. The Android runtime also provides a set of core
libraries which enable Android application developers to write Android applications
using standard Java programming language.
1701109

4) Application Framework
The Application Framework layer provides many higher-level services to applications in
the form of Java classes. Application developers are allowed to make use of these
services in their applications.
The Android framework includes the following key services −
• Activity Manager − Controls all aspects of the application lifecycle and activity
stack.
• Content Providers − Allows applications to publish and share data with other
applications.
• Resource Manager − Provides access to non-code embedded resources such as
strings, color settings and user interface layouts.
• Notifications Manager − Allows applications to display alerts and notifications
to the user.
• View System − An extensible set of views used to create application user
interfaces.

5) Applications
All the Android applications are at the top layer. The applicationsare installed on this
layer only. Examples of such applications are Contacts Books, Browser, Games etc.

ANDROID STUDIO:
Android Studio is the official integrated development environment (IDE) for Google’s
Android operating system, built on JetBrains' IntelliJ IDEA software and designed specifically
for Android development.It is available for download on Windows, macOS and Linux based
operating systems. It is a replacement for the Eclipse Android Development Tools (ADT) as the
primary IDE for native Android application development.

Android Studio was announced on May 16, 2013 at the Google I/O conference. The first
stable build was released in December 2014, starting from version 1.0.Since May 7,
2019, Kotlin is Google’s preferredlanguage for Android app development.Still, other
programming languages are supported by Android Studio, such as Java and C++.
Features:
1) Gradle-based build support
2) Android-specific refactoring and quick fixes
3) Lint tools to catch performance, usability, version compatibility and other problems
4) ProGuard integration and app-signing capabilities
5) Template-based wizards to create common Android designs and components
6) A rich layout editor that allows users to drag-and-drop UI components, option
to preview layouts on multiple screen configurations
7) Support for building Android Wear apps
8) Built-in support for Google Cloud Platform, enabling integration with Firebase Cloud
Messaging (Earlier 'Google Cloud Messaging') and Google App Engine
9) Android Virtual Device (Emulator) to run and debug apps in the Android studio.
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2

TOTAL 20

RESULT:
Thus, the study on Android and Android Studio was completed successfully.
1701109

EX NO:2 ANDROID APP FOR LAYOUT GUI COMPONENTS FONTS AND COLORS

DATE:
13.12.19

AIM:
To develop a Simple Android Application that uses GUI components, Font and Colors.

PROCEDURE:

Creating a New project:

Step 1: Open Android Studio and then click on File -> New -> New project.

Step 2: Then type the Application name as “APP1″ and click Next.
Step 3: Then select the Minimum SDK as shown below and click next.
Step 4: Then select the Empty Activity and click next.
Step 5: Finally click Finish.
Designing layout for the Android Application:

Step1: Click on app -> res -> layout -> activity_main.xml.

Step2: Click on Text.

Step 3: Type the source code for activity main.xml


Step4: Now click on design and the application appears the designing part is completed.
Java Coding for the Android Application:

Step1: Click on app -> java -> com.example.app1 -> Main Activity.

Step2: Type the source code for main activity.java.The main coding part is completed.
Step3: Run the application to view the output. Click Run.
SOURCE CODE:

Coding for activity main.xml


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

<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:text="Change font size"
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"
android:textSize="25sp" />
</LinearLayout>
1701109

Coding for main.activity.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;
public class MainActivity extends AppCompatActivity
{ int ch=1;
float font=30;
@Override
protected void onCreate(Bundle savedInstanceState)

{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView t= (TextView) findViewById(R.id.textView);
Button b1= (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
t.setTextSize(font);
font = font + 5;
if (font == 50)
font = 30;
}});
Button b2= (Button) findViewById(R.id.button2);
b2.setOnClickListener(new View.OnClickListener() {
1701109

@Override
public void onClick(View v) {
switch (ch) {
case 1:

t.setTextColor(Color.RED);
break;
case 2:
t.setTextColor(Color.CYAN);
break;
case 3:

t.setTextColor(Color.MAGENTA);
break;
} ch++;

if (ch == 3)
ch = 1;
}

});
}}
1701109

OUTPUT:

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2

TOTAL 20

RESULT:
Thus an application was developed that uses GUI components, fonts and colors and
executed successfully.
1701109

EX NO 3
ANDROID APPLICATION FOR LAYOUT MANAGERS AND EVENT LISTENERS

DATE:
20.12.19

AIM:
To develop a Simple Android Application that uses layout managers and event listeners.
PROCEDURE:

Creating a New project:

Step 1: Open Android Studio and then click on File -> New -> New project.

Step 2: Then type the Application name as “APP2″ and click Next.
Step 3: Then select the Minimum SDK as shown below and click next.
Step 4: Then select the Empty Activity and click next.
Step 5: Finally click Finish.

Step6: click on File->new->activity->empty activity

Step7: type the activity name as, Second Activity and click finish.
Designing layout for the Android Application:

Step1: Click on app -> res -> layout -> activity_main.xml.

Step2: Click on Text.


Step 3: Type the source code for activity main.xml
Step4: click on app->res->layout-> activity second.xml
Step5: click on text

Step6: Now click on design and the application appears the designing part is completed.
Java Coding for the Android Application:

Step1: Click on app -> java -> com.example.app2 -> Main Activity.

Step2: Type the source code for main activity.java.The main coding part is completed.
Step3: click on app->java->com.example.app2->Second activity
Step4: Run the application to view the output. Click Run.
1701109

SOURCE CODE:

Coding for main.xml

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

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

<LinearLayout

android:layout_width="match_parent"

android:layout_height="100dp">

<TextView

android:id="@+id/textView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="30dp"

android:text="Details Form"

android:textSize="25sp"

android:gravity="center"/>

</LinearLayout>

<GridLayout

android:id="@+id/gridLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_marginTop="100dp"
1701109

android:layout_marginBottom="200dp"

android:columnCount="2"

android:rowCount="3">

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:layout_row="0"

android:layout_column="0"

android:text="Name"

android:textSize="20sp"

android:gravity="center"/>

<EditText

android:id="@+id/editText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:layout_row="0"

android:layout_column="1"

android:ems="10"/>

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
1701109

android:layout_margin="10dp"

android:layout_row="1"

android:layout_column="0"

android:text="Reg.No"

android:textSize="20sp"

android:gravity="center"/>

<EditText

android:id="@+id/editText2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:layout_row="1"

android:layout_column="1"

android:inputType="number"

android:ems="10"/>

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:layout_row="2"

android:layout_column="0"

android:text="Dept"

android:textSize="20sp"

android:gravity="center"/>
1701109

<Spinner

android:id="@+id/spinner"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="10dp"

android:layout_row="2"

android:layout_column="1"

android:spinnerMode="dropdown"/>

</GridLayout>

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_centerInParent="true"

android:layout_marginBottom="150dp"

android:text="Submit"/>

</RelativeLayout>

Coding for activitysecond.xml

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

<LinearLayout 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="com.example.devang.exno2.SecondActivity"
1701109

android:orientation="vertical"

android:gravity="center">

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="20dp"

android:text="New Text"

android:textSize="30sp"/>

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="20dp"

android:text="New Text"

android:textSize="30sp"/>

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="20dp"

android:text="New Text"

android:textSize="30sp"/>

</LinearLayout>
1701109

Coding for mainactivity.java:

package com.example.exno2;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Spinner;

public class MainActivity extends AppCompatActivity {

//Defining the Views

EditText e1,e2;

Button bt;

Spinner s;

//Data for populating in Spinner

String [] dept_array={"CSE","ECE","IT","Mech","Civil"};

String name,reg,dept;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//Referring the Views

e1= (EditText) findViewById(R.id.editText);

e2= (EditText) findViewById(R.id.editText2);


1701109

bt= (Button) findViewById(R.id.button);

s= (Spinner) findViewById(R.id.spinner);

//Creating Adapter for Spinner for adapting the data from array to Spinner

ArrayAdapter adapter= new


ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_item,dept_array);

s.setAdapter(adapter);

//Creating Listener for Button

bt.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v)

//Getting the Values from Views(Edittext & Spinner)

name=e1.getText().toString();

reg=e2.getText().toString();

dept=s.getSelectedItem().toString();

//Intent For Navigating to Second Activity

Intent i = new Intent(MainActivity.this,SecondActivity.class);

//For Passing the Values to Second Activity

i.putExtra("name_key", name);

i.putExtra("reg_key",reg);

i.putExtra("dept_key", dept);

startActivity(i); }

});

}
1701109

Coding for second activity.java:

package com.example.exno2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class SecondActivity extends AppCompatActivity {


TextView t1,t2,t3;
String name,reg,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
t1= (TextView) findViewById(R.id.textView1);
t2= (TextView) findViewById(R.id.textView2);
t3= (TextView) findViewById(R.id.textView3);
//Getting the Intent
Intent i = getIntent();

//Getting the Values from First Activity using the Intent received
name=i.getStringExtra("name_key");
reg=i.getStringExtra("reg_key");
dept=i.getStringExtra("dept_key");
//Setting the Values to Intent
t1.setText(name);
t2.setText(reg);
t3.setText(dept);}}
1701109

OUTPUT:

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2

TOTAL 20

RESULT:

Thus an android application was developed that uses layout managers and event listeners
and output was executed successfully.
1701109

EX NO 4

SIMPLE ANDROID APPLICATION FOR NAÏVE CALCULATOR

DATE:
27.12.19

AIM:
To develop an android application for native simple calculator and perform various operations
to display the output.
PROCEDURE:

Creating a new project:


Step1: open android studio, click file->new->project.
Step2: type the application as “app3” and click next
Step3: select minimum SDK and click next
Step4: select empty activity and click next
Step5: click finish

Designing layout for android application:


Step1: click on app->re->layout->activity main.xml
Step2: type the source code for activity main.xml
Step3: now click on design, applin appears. Design part is completed.
Main JAVA coding program for android application:
Step1: click on app->java->com.example->app.3->main activity
Step2: type the source code for main.activity.java
Step3: run the appln to view the result. Click Run.
SOURCE CODE:
Code for activity main.xml:
<?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"
1701109

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

<Button
android:id="@+id/Add"
android:layout_width="match_parent"
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"
android:layout_weight="1"
1701109

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>
Code for main activity.java
package com.example.devang.exno3;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import android.text.TextUtils;
import android.view.View;

import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements OnClickListener
{
//Defining the Views
EditText Num1;
EditText Num2;
1701109

Button Add;
Button Sub;
Button Mul;
Button Div;
TextView Result;
@Override
public void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Referring the Views

Num1 = (EditText) findViewById(R.id.editText1);


Num2 = (EditText) findViewById(R.id.editText2);
Add = (Button) findViewById(R.id.Add);
Sub = (Button) findViewById(R.id.Sub);
Mul = (Button) findViewById(R.id.Mul);
Div = (Button) findViewById(R.id.Div);

Result = (TextView) findViewById(R.id.textView);


// set a listener
Add.setOnClickListener(this);
Sub.setOnClickListener(this);
Mul.setOnClickListener(this);
Div.setOnClickListener(this);}
@Override
public void onClick (View v)
{float num1 = 0;
float num2 = 0;
float result = 0;
1701109

String oper = "";


// check if the fields are empty
if (TextUtils.isEmpty(Num1.getText().toString()) ||
TextUtils.isEmpty(Num2.getText().toString()))
return;
// read EditText and fill variables with numbers
num1 = Float.parseFloat(Num1.getText().toString());
num2 = Float.parseFloat(Num2.getText().toString());

// defines the button that has been clicked and performs the corresponding operation
// write operation into oper, we will use it later for output
switch (v.getId())
{
case R.id.Add:
oper = "+";

result = num1 + num2;


break;
case R.id.Sub:
oper = "-";
result = num1 - num2;
break;

case R.id.Mul:
oper = "*";
result = num1 * num2;
break;
case R.id.Div:
oper = "/";

result = num1 / num2;


break;
1701109

default:
break;
}
// form the output line

Result.setText(num1 + " " + oper + " " + num2 + " = " + result);
}
}
OUTPTUT:
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5

PRE LAB PREPARATION 6


IN LAB PERFORMANCE 7

POST VIVA 2
TOTAL 20

RESULT:

Thus a Simple Android Application for Native Calculator is developed and


executed successfully
1701109

EX NO 5

DATE: ANDROID APPLICATION TO DRAW BASIC GRAPHICAL PRIMITIVES


3.1.20

AIM:

To develop a Simple Android Application that draws basic Graphical Primitives on the screen.

PROCEDURE:

Creating a new project:


Step1: open android studio, click file->new->project.
Step2: type the application as “app4” and click next
Step3: select minimum SDK and click next
Step4: select empty activity and click next
Step5: click finish

Designing layout for android application:


Step1: click on app->re->layout->activity main.xml
Step2: type the source code for activity main.xml
Step3: now click on design, applin appears. Design part is completed.
Main JAVA coding program for android application:
Step1: click on app->java->com.example->app.4->main activity

Step2: type the source code for main.activity.java


Step3: run the appln to view the result. Click Run.
SOURCE CODE:

Code for main activity.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">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>
1701109

Code for MainActivity.java


package com.example.exno4;
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;
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating a Bitmap
Bitmap bg = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);
//Setting the Bitmap as background for the ImageView
ImageView i = (ImageView) findViewById(R.id.imageView);
i.setBackgroundDrawable(new BitmapDrawable(bg));
//Creating the Canvas Object
Canvas canvas = new Canvas(bg);
//Creating the Paint Object and set its color & TextSize
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(50);
//To draw a Rectangle
canvas.drawText("Rectangle", 420, 150, paint);
canvas.drawRect(400, 200, 650, 700, paint);
//To draw a Circle
canvas.drawText("Circle", 120, 150, paint);
canvas.drawCircle(200, 350, 150, paint);
//To draw a Square
canvas.drawText("Square", 120, 800, paint);
canvas.drawRect(50, 850, 350, 1150, paint);
//To draw a Line
canvas.drawText("Line", 480, 800, paint);
canvas.drawLine(520, 850, 520, 1150, paint);
}
}
1701109

OUTPUT:

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5

PRE LAB PREPARATION 6


IN LAB PERFORMANCE 7

POST VIVA 2
TOTAL 20

RESULT:

Thus a Simple Android Application that draws basic Graphical Primitives on the screen
is developed and executed successfully.
1701109

EX NO 6
ANDROID APPLICATION THAT MAKES USE OF DATABASE
DATE:
10.1.20

AIM:

To develop a Simple Android Application that makes use of Database.

PROCEDURE:

Creating a new project:


Step1: open android studio, click file->new->project.
Step2: type the application as “app3” and click next
Step3: select minimum SDK and click next
Step4: select empty activity and click next

Step5: click finish


Designing layout for android application:
Step1: click on app->re->layout->activity main.xml
Step2: type the source code for activity main.xml
Step3: now click on design, applin appears. Design part is completed.
Main JAVA coding program for android application:

Step1: click on app->java->com.example->app.3->main activity


Step2: type the source code for main.activity.java
Step3: run the appln to view the result. Click Run.
SOURCE CODE:

Code for Activity_main.xml

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

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

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"

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

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

<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
1701109

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>

Code for main activity .java

package com.example.exno5;

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;
1701109

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

public class MainActivity extends Activity implements OnClickListener

EditText Rollno,Name,Marks;

Button Insert,Delete,Update,View,ViewAll;

SQLiteDatabase db;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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);
1701109

ViewAll.setOnClickListener(this);

// Creating database and table

db=openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);

db.execSQL("CREATE TABLE IF NOT EXISTS student(rollno VARCHAR,name


VARCHAR,marks VARCHAR);");

} public void onClick(View view)

// Inserting a record to the Student table

if(view==Insert)

// Checking for empty fields

if(Rollno.getText().toString().trim().length()==0||

Name.getText().toString().trim().length()==0||

Marks.getText().toString().trim().length()==0)

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


1701109

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;

}
1701109

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));
1701109

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());

}
1701109

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();

}
1701109

OUTPUT:

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5

PRE LAB PREPARATION 6


IN LAB PERFORMANCE 7

POST VIVA 2
TOTAL 20

RESULT:

Thus a Simple Android Application that makes use of Database is developed and
executed successfully.
1701109
1701109
1701109

EX NO 7
ANDROID APPLICATION THAT WRITES DATA TO THE SD CARD

DATE:
24.1.20

AIM:

To develop an Android Application that writes data to the SD Card.

PROCEDURE:

Creating a New project:

Step1: Open Android Studio and then click on File -> New -> New project.
Step2: Then type the Application name as “app6″ and click Next.
Step3: Then select the Minimum SDK as shown below and click next.
Step4: Then select the Empty Activity and click next.
Step5: Finally click Finish.
Designing layout for the Android Application:

Step1:Click on app -> res -> layout -> activity_main.xml.


Step2:click on text.
Step3: type the source code for activity main.xml
Step4: click on design. Now designing part is completed.
Adding permissions in Manifest for the Android Application:

Step1: Click on app -> manifests -> AndroidManifest.xml


Step2: Now include the WRITE EXTERNALSTORAGE permissions in the
AndroidManifest.xml file
Step3: type the source code for Android manifest.xml.
Java Coding for the Android Application:
Step1: Click on app -> java -> com.example.exno6 -> Main Activity.
Step2: Type the source code for main activity.java. The main coding part is completed.
Step3: Run the application to view the result. Click Run.
SOURCE CODE:
Code for activity main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
1701109

android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30dp" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
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>
Code for android manifest.xml:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exno6"

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

<activity android:name=".MainActivity"
1701109

<intent-filter

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter></activity></application></manifest>

Code for main activity.java

package com.example.exno9;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

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;

public class MainActivity extends AppCompatActivity

{ EditText e1;

Button write,read,clear;

@Override

protected void onCreate(Bundle savedInstanceState)

{ super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

e1= (EditText) findViewById(R.id.editText);


1701109

write= (Button) findViewById(R.id.button);

read= (Button) findViewById(R.id.button2);

clear= (Button) findViewById(R.id.button3);

write.setOnClickListener(new View.OnClickListener()

{ @Override

public void onClick(View v)

{ String message=e1.getText().toString();

try

File f=new File("/sdcard/myfile.txt");

f.createNewFile();

FileOutputStream fout=new FileOutputStream(f);

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

public void onClick(View v)

{ String message;
1701109

String buf = ""; try

File f = new File("/sdcard/myfile.txt");

FileInputStream fin = new FileInputStream(f);

BufferedReader br = new BufferedReader(new InputStreamReader(fin));

while ((message = br.readLine()) != null)

buf += message;

e1.setText(buf);

br.close();

fin.close();

Toast.makeText(getBaseContext(),"Data Recived from


SDCARD",Toast.LENGTH_LONG).show();

catch (Exception e)

Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_LONG).show();

});

clear.setOnClickListener(new View.OnClickListener()

@Override
1701109

public void onClick(View v)

e1.setText("");

});

OUTPUT:
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5

PRE LAB PREPARATION 6


IN LAB PERFORMANCE 7

POST VIVA 2
TOTAL 20

RESULT:

Thus an android application was created to write data and fetch to SD card successfully
and output was displayed.
1701109

EX NO 8
DEVELOP AN APPLICATION TO CAPTURE IMAGE USING BUILT IN CAMERA

DATE:
24.1.20

AIM:

To develop an android application to capture an image using built in camera.

CONTENT:

The android framework provides the facility of working with camera in 2 ways:

1)by using existing camera application

2)by using camera API

PROGRAM PROCEDURE:

Step1: create a new project in Android studio. Name it camera code example.

Step2: open res->layout->xml. Type the source code for frame layout.

Step3: open src->package->main activity.java. Load the fragment into fragment layout in main
activity.

Step4: open res->layout->xml [ camera fragment]

Step5: use different camera fragment

Step6: open src->package->camerafragment.java

Step7: open src->package->database handler

Step8: open src->layout->xml [local fragment]

Step9: open src->package->local response.java

Step10: open src->package->local fragment.java

Step11: open src->layout->xml [local database items.xml]

Step12: open src->package->local database adapter.java

Step13: generate the output by running the app.


1701109

SOURCE CODE:

frame layout to load fragments.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<FrameLayout

android:id="@+id/frameLayout"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

</RelativeLayout>

fragment into frame layout in MainActivity:

import android.Manifest;

import android.app.Activity;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.graphics.Bitmap;

import android.os.Build;

import android.support.annotation.NonNull;

import android.support.annotation.Nullable;

import android.support.annotation.RequiresApi;

import android.support.v4.app.Fragment;

import android.support.v4.app.FragmentTransaction;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;
1701109

import android.view.View;

import android.widget.FrameLayout;

import android.widget.ImageView;

import android.widget.TextView;

import android.widget.Toast;

import com.example.cameracodeexample.Fragments.CameraFragment;

public class MainActivity extends AppCompatActivity {

FrameLayout frameLayout;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

loadFragment(new CameraFragment(), false); }

public void loadFragment(Fragment fragment, Boolean bool) {

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

transaction.replace(R.id.frameLayout, fragment);

if (bool)

transaction.addToBackStack(null);

transaction.commit();

}}

Camera fragment:

<TextView

android:id="@+id/text"

android:layout_width="match_parent"

android:layout_height="wrap_content"
1701109

android:text="Save Image"

android:layout_gravity="center"

android:layout_margin="@dimen/_12sdp"

android:textSize="@dimen/_18sdp"

android:textAlignment="center"

android:background="#EBEBEB"/>

TextView

<android:id="@+id/text1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="View Image"

android:layout_gravity="center"

android:layout_margin="@dimen/_12sdp"

android:textSize="@dimen/_18sdp"

android:textAlignment="center"

android:background="#EBEBEB"

android:layout_below="@id/text"/>

camera fragment.java

import android.Manifest;

import android.app.Activity;

import android.content.ContentValues;

import android.content.Context;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.database.sqlite.SQLiteDatabase;
1701109

import android.graphics.Bitmap;

import android.os.Build;

import android.os.Bundle;

import android.support.annotation.NonNull;

import android.support.annotation.Nullable;

import android.support.annotation.RequiresApi;

import android.support.v4.app.Fragment;

import android.util.Base64;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.TextView;

import android.widget.Toast;

import com.example.cameracodeexample.MainActivity;

import com.example.cameracodeexample.R;

import com.example.cameracodeexample.utils.DataBaseHandler;

import java.io.ByteArrayOutputStream;

public class CameraFragment extends Fragment {

private static final int CAMERA_REQUEST = 1888;

TextView text,text1;

private static final int MY_CAMERA_PERMISSION_CODE = 100;

//Bitmap photo;

String photo;

DataBaseHandler databaseHandler;

private SQLiteDatabase db;


1701109

Bitmap theImage;

@Nullable

@Override

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup


container, @Nullable Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.camera_fragment,container,false);

// imageView =view. findViewById(R.id.imageView1);

text = view.findViewById(R.id.text);

text1 = view.findViewById(R.id.text1);

databaseHandler = new DataBaseHandler(getContext());

text.setOnClickListener(new View.OnClickListener() {

@RequiresApi(api = Build.VERSION_CODES.M)

@Override

public void onClick(View v) {

if (getActivity().checkSelfPermission(Manifest.permission.CAMERA) !=
PackageManager.PERMISSION_GRANTED)

{ requestPermissions(new String[]{Manifest.permission.CAMERA},
MY_CAMERA_PERMISSION_CODE);

else

Intent cameraIntent = new


Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(cameraIntent, CAMERA_REQUEST);

}); text1.setOnClickListener(new View.OnClickListener() {


1701109

@Override

public void onClick(View v) {

((MainActivity) getActivity()).loadFragment(new LocalFragment(), true);

});

return view;

}private void setDataToDataBase() {

db = databaseHandler.getWritableDatabase();

ContentValues cv = new ContentValues();

cv.put(databaseHandler.KEY_IMG_URL,photo);

long id = db.insert(databaseHandler.TABLE_NAME, null, cv);

if (id < 0) {

Toast.makeText(getContext(), "Something went wrong. Please try again later...",


Toast.LENGTH_LONG).show();

} else {

Toast.makeText(getContext(), "Add successful", Toast.LENGTH_LONG).show();

}@Override

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,


@NonNull int[] grantResults) {

super.onRequestPermissionsResult(requestCode, permissions, grantResults);

if (requestCode == MY_CAMERA_PERMISSION_CODE)

if (grantResults[0] == PackageManager.PERMISSION_GRANTED)

{
1701109

Toast.makeText(getActivity(), "camera permission granted",


Toast.LENGTH_LONG).show();

Intent cameraIntent = new


Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

startActivityForResult(cameraIntent, CAMERA_REQUEST);

else

Toast.makeText(getActivity(), "camera permission denied",


Toast.LENGTH_LONG).show();

} @Override

public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK)

theImage = (Bitmap) data.getExtras().get("data");

photo=getEncodedString(theImage);

setDataToDataBase();

}private String getEncodedString(Bitmap bitmap){

ByteArrayOutputStream os = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.JPEG,100, os);
bitmap.compress(Bitmap.CompressFormat.PNG, (0–100 compression), os);*/

byte[] imageArr = os.toByteArray();

return Base64.encodeToString(imageArr, Base64.URL_SAFE);}}


1701109

code for database class handler.java

import android.content.Context;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHandler extends SQLiteOpenHelper {

public Context context;

public static final String DATABASE_NAME = "dataManager";

public static final int DATABASE_VERSION = 1;

public static final String TABLE_NAME = "data";

public static final String KEY_ID = "id";

public static final String KEY_IMG_URL = "ImgFavourite";

public DataBaseHandler(Context context) {

super(context, DATABASE_NAME, null, DATABASE_VERSION);

this.context = context;

//Toast.makeText(context, "Constructor called", Toast.LENGTH_LONG).show(); }

public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(" +
KEY_ID +

" INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_IMG_URL + " TEXT" +


")";

public static final String DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME +
""; @Override

public void onCreate(SQLiteDatabase db) {

db.execSQL(CREATE_TABLE);}

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

db.execSQL(DROP_TABLE);
1701109

onCreate(db);

} public void deleteEntry(long row) {

SQLiteDatabase sqLiteDatabase = getWritableDatabase();

sqLiteDatabase.delete(TABLE_NAME, KEY_ID + "=" + row, null);}}

code for local database adapter.java

import android.content.Context;

import android.content.DialogInterface;

import android.database.sqlite.SQLiteDatabase;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.support.annotation.NonNull;

import android.support.v7.app.AlertDialog;

import android.support.v7.widget.RecyclerView;

import android.util.Base64;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import java.util.ArrayList;

public class LocalDataBaseAdapter extends RecyclerView.Adapter {

Context context;

ArrayList singleRowArrayList;

SQLiteDatabase db;

DataBaseHandler myDatabase;
1701109

public LocalDataBaseAdapter(Context context, ArrayList singleRowArrayList,


SQLiteDatabase db, DataBaseHandler myDatabase) {

this.context = context;

this.singleRowArrayList = singleRowArrayList;

this.db = db;

this.myDatabase = myDatabase; }

@NonNull

@Override

public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

View view = LayoutInflater.from(context).inflate(R.layout.local_database_items, null);

MyViewHolder myViewHolder = new MyViewHolder(view);

return myViewHolder;

} @Override

public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int i)

myViewHolder.newsImage.setImageBitmap(getBitmapFromEncodedString(singleRowArrayList
.get(i).image));

myViewHolder.delete.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

deletedata(i,singleRowArrayList);

});} @Override

public int getItemCount() {

return singleRowArrayList.size();

}
1701109

class MyViewHolder extends RecyclerView.ViewHolder {

ImageView newsImage,delete;

public MyViewHolder(@NonNull View itemView) {

super(itemView);

newsImage = (ImageView) itemView.findViewById(R.id.newsImage);

delete = (ImageView) itemView.findViewById(R.id.delete);

} public void deletedata(final int position, final ArrayList singleRowArrayList){

new AlertDialog.Builder(context)

.setIcon(R.drawable.defaultimage)

.setTitle("Delete result")

.setMessage("Are you sure you want delete this result?")

.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

/* This is where deletions should be handled */

myDatabase.deleteEntry(singleRowArrayList.get(position).getUid());

singleRowArrayList.remove(position);

notifyItemRemoved(position);

notifyDataSetChanged();

myDatabase.close();

//((MainActivity) context).loadFragment(new LocalFragment(), true); }

})

.setNegativeButton("No", null)
1701109

.show();

}private Bitmap getBitmapFromEncodedString(String encodedString){

byte[] arr = Base64.decode(encodedString, Base64.URL_SAFE);

Bitmap img = BitmapFactory.decodeByteArray(arr, 0, arr.length);

return img; }}

OUTPUT:

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5

PRE LAB PREPARATION 6


IN LAB PERFORMANCE 7

POST VIVA 2
TOTAL 20

RESULT:

Thus an android application was created to capture an image using built in camera
successfully.
1701109

EX NO 9 ANDROID APPLICATION THAT CREATES AN ALERT UPON


DATE: RECEIVING A MESSAGE
31.1.20

AIM:

To develop an Android Application that creates an alert upon receiving a message.

PROCEDURE:

Creating a new project:


Step1: open android studio, click file->new->project.
Step2: type the application as “app8” and click next
Step3: select minimum SDK and click next

Step4: select empty activity and click next


Step5: click finish
Step6: Build and load the project. Click on file->new->Activity->Empty Activity.
Step7: type the activity name Second Activity and click finish.
Designing layout for android application:
Step1: click on app->re->layout->activity main.xml click TEXT.

Step2: type the source code for activity main.xml


Step3: now click on design, application appears. Design part is completed.
Main JAVA coding program for android application:
Step1: click on app->java->com.example->app.8->main activity
Step2: type the source code for main.activity.java
Step3: run the appln to view the result. Click Run.

SOURCE CODE:

Code for main activity .xml

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical">
1701109

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:textSize="30sp" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textSize="30sp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_gravity="center"
android:text="Notify"
android:textSize="30sp"/>
</LinearLayout>
Code for main activity .java

package com.example.exno10;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

public class MainActivity extends AppCompatActivity

{ Button notify;

EditText e;
1701109

@Override

protected void onCreate(Bundle savedInstanceState)

{ super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

notify= (Button) findViewById(R.id.button);

e= (EditText) findViewById(R.id.editText);

notify.setOnClickListener(new View.OnClickListener()

@Override

public void onClick(View v)

Intent intent = new Intent(MainActivity.this, SecondActivity.class);

PendingIntent pending = PendingIntent.getActivity(MainActivity.this, 0, intent, 0);

Notification noti = new Notification.Builder(MainActivity.this).setContentTitle("New


Message").setContentText(e.getText().toString()).setSmallIcon(R.mipmap.ic_launcher).setConte
ntIntent(pending).build();

NotificationManager manager = (NotificationManager)


getSystemService(NOTIFICATION_SERVICE);

noti.flags |= Notification.FLAG_AUTO_CANCEL;

manager.notify(0, noti);

});

}
1701109

OUTPUT:

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2
TOTAL 20

RESULT:
Thus Android Application that creates an alert upon receiving a message is developed and
executed successfully.
1701109

EXNO 10

ANDROID APPLICATION THAT CREATES ALARM CLOCK


DATE:
7.2.20

AIM:

To develop an Android Application that creates Alarm Clock.

PROCEDURE:

To create a new project

Step1: Open Android Studio and then click on File -> New -> New project.

Step2: type the application name “app9”, click next.

Step3: Then select the Minimum SDK as shown below and click next.

Step4: Then select the Empty Activity and click Next.

Step5: click finish

Step6: click on file->new->activity->empty activity.

Step7: type the activity name alarm receiver. Click finish.

Design layout for android application:

Step1: Click on File -> New -> Activity -> Empty Activity.

Step2: Type the Activity Name as Alarm Receiver and click Finish button.

Step3: type the source code for activity main.xml where design part will be completed.

Changes in Manifest for the Android Application:

Step1: Click on app -> manifests -> AndroidManifest.xml

Step2: change the activity tag to receiver tag in the AndroidManifest.xml file

Step3: type the source code for android manifest.xml. Changes are done in manifest.

Java coding for android application:

Step1: Click on app -> java -> com.example.app9 -> MainActivity.

Step2: type the source code for main activity.java

Step3: Click on app -> java -> com.example.app9 -> AlarmReceiver.


1701109

Step4: type the source code for alarm receiver.java

Step5: run the app to see the output.

SOURCE CODE:

Code for activity main.xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TimePicker

android:id="@+id/timePicker"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center" />

<ToggleButton

android:id="@+id/toggleButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:layout_margin="20dp"

android:checked="false"

android:onClick="OnToggleClicked" />

</LinearLayout>
1701109

Code for android manifest.xml:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.exno11" >

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

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter></activity>

<receiver android:name=".AlarmReceiver" >

</receiver></application></manifest>

Code for mainactivity.java:

package com.example.exno11;

import android.app.AlarmManager;

import android.app.PendingIntent;

import android.content.Intent;

import android.os.Bundle;
1701109

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.TimePicker;

import android.widget.Toast;

import android.widget.ToggleButton;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity

{ TimePicker alarmTimePicker;

PendingIntent pendingIntent;

AlarmManager alarmManager;

@Override

protected void onCreate(Bundle savedInstanceState)

{ super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

alarmTimePicker = (TimePicker) findViewById(R.id.timePicker);

alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

} public void OnToggleClicked(View view)

long time;

if (((ToggleButton) view).isChecked())

Toast.makeText(MainActivity.this, "ALARM ON", Toast.LENGTH_SHORT).show();

Calendar calendar = Calendar.getInstance();


1701109

calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());

calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());

Intent intent = new Intent(this, AlarmReceiver.class);

pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));

if(System.currentTimeMillis()>time)

{ if (calendar.AM_PM == 0)

time = time + (1000*60*60*12);

else

time = time + (1000*60*60*24); }

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 10000,


pendingIntent);

}else

alarmManager.cancel(pendingIntent);

Toast.makeText(MainActivity.this, "ALARM OFF",


Toast.LENGTH_SHORT).show();}}}

Code for alarm receiver.java:

package com.example.exno11;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.media.Ringtone;

import android.media.RingtoneManager;
1701109

import android.net.Uri;

import android.widget.Toast;

public class AlarmReceiver extends BroadcastReceiver

{ @Override

public void onReceive(Context context, Intent intent)

Toast.makeText(context, "Alarm! Wake up! Wake up!", Toast.LENGTH_LONG).show();

Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

if (alarmUri == null)

{ alarmUri =
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);

ringtone.play();}}

OUTPUT:
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5

PRE LAB PREPARATION 6


IN LAB PERFORMANCE 7
POST VIVA 2
TOTAL 20

RESULT:

Thus Android Application that creates Alarm Clock is developed and executed successfully.
1701109

EX NO 11
DEMONSTRATE ACTIVITY CLASS TO SHOW DIFFERENT EVENTS
DATE:
14.2.20

AIM:

To develop Android Application that creates Alarm Clock is developed and


executed successfully.

Java Coding for the Android Application:

Step1: Click on app -> java -> com.example.exno 9 -> Main Activity.

Step2: type the source code for main activity. Java

Step3: coding part is completed.

Step4: alarm receiver java coding

Click on app -> java -> com.example.exno 9 -> Alarm Receiver.

Step5: type the source code for alarm receiver.java

Step6: Run the app to see the output

SOURCE CODE:

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

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
android:layout_width="match_parent"
android:layout_height="match_parent"

android:orientation="vertical">
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:checked="false"
1701109

android:onClick="OnToggleClicked" />
</LinearLayout>
Android manifest.xml:

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exno11" >
<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" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".AlarmReceiver" >
</receiver>
</application>
</manifest>
Mainactivity.java

package com.example.exno11;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity


{
TimePicker alarmTimePicker;
PendingIntent pendingIntent;
AlarmManager alarmManager;

@Override
protected void onCreate(Bundle savedInstanceState)
{
1701109

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alarmTimePicker = (TimePicker) findViewById(R.id.timePicker);
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
}
public void OnToggleClicked(View view)
{
long time;
if (((ToggleButton) view).isChecked())
{
Toast.makeText(MainActivity.this, "ALARM ON",
Toast.LENGTH_SHORT).show();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, alarmTimePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, alarmTimePicker.getCurrentMinute());
Intent intent = new Intent(this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

time=(calendar.getTimeInMillis()-(calendar.getTimeInMillis()%60000));
if(System.currentTimeMillis()>time)
{
if (calendar.AM_PM == 0)
time = time + (1000*60*60*12);
else
time = time + (1000*60*60*24);
}
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, 10000,
pendingIntent);
}
else
{
alarmManager.cancel(pendingIntent);
Toast.makeText(MainActivity.this, "ALARM OFF",
Toast.LENGTH_SHORT).show();
}
}
}
Alarm receiver:

package com.example.exno11;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.widget.Toast;
public class AlarmReceiver extends BroadcastReceiver
{@Override
1701109

public void onReceive(Context context, Intent intent)


{
Toast.makeText(context, "Alarm! Wake up! Wake up!",
Toast.LENGTH_LONG).show();
Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if (alarmUri == null)
{
alarmUri =
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
} Ringtone ringtone = RingtoneManager.getRingtone(context, alarmUri);
ringtone.play();}}
OUTPUT:
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2
TOTAL 20

RESULT:

Thus Android Application that creates Alarm Clock is developed and


executed successfully.
1701109

EXNO 12 DEVELOP A PROGRAM TO SEND A USER FROM ONE APPLICATON TO ANOTHER

DATE:
21.2.20

AIM:

To develop an android application to demonstrate user to send one app to other app and
display the output.

PROCEDURE:

Step1: create a new project in android studio.

File> new> new project.

Step2: type the source code for res layout activity.xml. One type of text is created.

Step3: type the source code for src main activity.java

[step2: app 1 <->step3: app2]

How to run?

1) To run the app from android studio, open one of your projects file activity and click RUN.

2) select your mobile device as an option.

3) check your mobile device which will display default screen.

4) when you click the default screen, the original application displays as an output.

SOURCE CODE:

code to res/layout/activity_main.xml.

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/parent"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity"

android:gravity="center"

android:background="#33FFFF00"
1701109

android:orientation="vertical">

<TextView

android:id="@+id/text"

android:textSize="18sp"

android:text="Click to open youtube"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

</LinearLayout>

code to src/MainActivity.java:

package com.example.andy.myapplication;

import android.content.Intent;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.LinearLayout;

import android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

int view = R.layout.activity_main;

TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(view);

final LinearLayout parent = findViewById(R.id.parent);

textView = findViewById(R.id.text);

textView.setOnClickListener(new View.OnClickListener() {
1701109

@Override

public void onClick(View v) {

Intent launchIntent =
getPackageManager().getLaunchIntentForPackage("com.google.android.youtube"); if
(launchIntent != null) {

startActivity(launchIntent);

} else {

Toast.makeText(MainActivity.this, "There is no package available in android",


Toast.LENGTH_LONG).show();

}}});}}

OUTPUT:
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2

TOTAL 20

RESULT:

Thus an application was developed to send user app to other app and output was
generated successfully.
1701109

EXNO 13
PROGRAM TO PLAY AUDIO AND VIDEO FILES

DATE:
28.2.20

AIM:

To develop an app to play audio/video files or as a media player and display the output.

PROCEDURE:

Step1: content of modified main activity

Src main activity.java

Step2: content o xml file

Res layout activity.main.xml

Step3: content of res values string.xml file

Step4: content of android manifest.xml file

Step5: run the app from android studio (actual android mobile device is connected with the
computer)

Step6: click RUN from any projects file activity and display the output.

SOURCE CODE:

Code for src main activity.java

package com.example.sairamkrishna.myapplication;

import android.app.Activity;

import android.media.MediaPlayer;

import android.os.Bundle;

import android.os.Handler;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.SeekBar;

import android.widget.TextView;

import android.widget.Toast;
1701109

import java.util.concurrent.TimeUnit;

public class MainActivity extends Activity {

private Button b1,b2,b3,b4;

private ImageView iv;

private MediaPlayer mediaPlayer;

private double startTime = 0;

private double finalTime = 0;

private Handler myHandler = new Handler();;

private int forwardTime = 5000;

private int backwardTime = 5000;

private SeekBar seekbar;

private TextView tx1,tx2,tx3;

public static int oneTimeOnly = 0;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

b1 = (Button) findViewById(R.id.button);

b2 = (Button) findViewById(R.id.button2);

b3 = (Button)findViewById(R.id.button3);

b4 = (Button)findViewById(R.id.button4);

iv = (ImageView)findViewById(R.id.imageView);

tx1 = (TextView)findViewById(R.id.textView2);

tx2 = (TextView)findViewById(R.id.textView3);

tx3 = (TextView)findViewById(R.id.textView4);

tx3.setText("Song.mp3");

mediaPlayer = MediaPlayer.create(this, R.raw.song);


1701109

seekbar = (SeekBar)findViewById(R.id.seekBar);

seekbar.setClickable(false);

b2.setEnabled(false);

b3.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(), "Playing

sound",Toast.LENGTH_SHORT).show();

mediaPlayer.start();

finalTime = mediaPlayer.getDuration();

startTime = mediaPlayer.getCurrentPosition();

if (oneTimeOnly == 0) {

seekbar.setMax((int) finalTime);

oneTimeOnly = 1;

} tx2.setText(String.format("%d min, %d sec",

TimeUnit.MILLISECONDS.toMinutes((long) finalTime),

TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -

TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)

finalTime)))

);tx1.setText(String.format("%d min, %d sec",

TimeUnit.MILLISECONDS.toMinutes((long) startTime),

TimeUnit.MILLISECONDS.toSeconds((long) startTime) -

TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)

startTime))));

seekbar.setProgress((int)startTime);

myHandler.postDelayed(UpdateSongTime,100);

b2.setEnabled(true);
1701109

b3.setEnabled(false);}});

b2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(), "Pausing

sound",Toast.LENGTH_SHORT).show();

mediaPlayer.pause();

b2.setEnabled(false);

b3.setEnabled(true);}});

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

int temp = (int)startTime;

if((temp+forwardTime)<=finalTime){

startTime = startTime + forwardTime;

mediaPlayer.seekTo((int) startTime);

Toast.makeText(getApplicationContext(),"You have Jumped forward 5

seconds",Toast.LENGTH_SHORT).show();

}else{

Toast.makeText(getApplicationContext(),"Cannot jump forward 5

seconds",Toast.LENGTH_SHORT).show();}}});

b4.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

int temp = (int)startTime;

if((temp-backwardTime)>0){

startTime = startTime - backwardTime;


1701109

mediaPlayer.seekTo((int) startTime);

Toast.makeText(getApplicationContext(),"You have Jumped backward 5

seconds",Toast.LENGTH_SHORT).show();

}else{

Toast.makeText(getApplicationContext(),"Cannot jump backward 5

seconds",Toast.LENGTH_SHORT).show();}}});}

private Runnable UpdateSongTime = new Runnable() {

public void run() {

startTime = mediaPlayer.getCurrentPosition();

tx1.setText(String.format("%d min, %d sec",

TimeUnit.MILLISECONDS.toMinutes((long) startTime),

TimeUnit.MILLISECONDS.toSeconds((long) startTime) -

TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.

toMinutes((long) startTime))));

seekbar.setProgress((int)startTime);

myHandler.postDelayed(this, 100);

}};}

Code for res/layout/activity_main.xml.

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

<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=".MainActivity">
1701109

<TextView android:text="Music Palyer" android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/textview"

android:textSize="35dp"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Tutorials point"

android:id="@+id/textView"

android:layout_below="@+id/textview"

android:layout_centerHorizontal="true"

android:textColor="#ff7aff24"

android:textSize="35dp" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/imageView"

android:layout_below="@+id/textView"

android:layout_centerHorizontal="true"

android:src="@drawable/abc"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/forward"

android:id="@+id/button"
1701109

android:layout_alignParentBottom="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/pause"

android:id="@+id/button2"

android:layout_alignParentBottom="true"

android:layout_alignLeft="@+id/imageView"

android:layout_alignStart="@+id/imageView" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/back"

android:id="@+id/button3"

android:layout_alignTop="@+id/button2"

android:layout_toRightOf="@+id/button2"

android:layout_toEndOf="@+id/button2" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/rewind"

android:id="@+id/button4"

android:layout_alignTop="@+id/button3"

android:layout_toRightOf="@+id/button3"

android:layout_toEndOf="@+id/button3" />
1701109

<SeekBar

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/seekBar"

android:layout_alignLeft="@+id/textview"

android:layout_alignStart="@+id/textview"

android:layout_alignRight="@+id/textview"

android:layout_alignEnd="@+id/textview"

android:layout_above="@+id/button" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceSmall"

android:text="Small Text"

android:id="@+id/textView2"

android:layout_above="@+id/seekBar"

android:layout_toLeftOf="@+id/textView"

android:layout_toStartOf="@+id/textView" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceSmall"

android:text="Small Text"

android:id="@+id/textView3"

android:layout_above="@+id/seekBar"

android:layout_alignRight="@+id/button4"

android:layout_alignEnd="@+id/button4" />
1701109

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="Medium Text"

android:id="@+id/textView4"

android:layout_alignBaseline="@+id/textView2"

android:layout_alignBottom="@+id/textView2"

android:layout_centerHorizontal="true" />

</RelativeLayout>

Code for res/values/string.xml.

<resources>

<string name="app_name">My Application</string>

<string name="back"><![CDATA[<]]></string>

<string name="rewind"><![CDATA[<<]]></string>

<string name="forward"><![CDATA[>>]]></string>

<string name="pause">||</string>

</resources>

Code for AndroidManifest.xml file.

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.sairamkrishna.myapplication" >

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >
1701109

<activity

android:name="com.example.sairamkrishna.myapplication.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

</manifest>

OUTPUT:
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2

TOTAL 20

RESULT:

Thus an android app was developed to demonstrate audio/video files and output was
displayed successfully.
1701109

EXNO 14
DEVELOP A PROGRAM TO SEND SMS

DATE:
28.2.20

AIM:

To develop an app to send user SMS and get its reply and to display it as an output.

PROCEDURE:

In Android, you can use SmsManager API or devices Built-in SMS application to send
SMS's.

1) SmsManager API

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);

2) Built-in SMS application

Intent sendIntent = new Intent(Intent.ACTION_VIEW);

sendIntent.putExtra("sms_body", "default content");

sendIntent.setType("vnd.android-dir/mms-sms");

startActivity(sendIntent);

3) Of course, both need SEND_SMS permission.

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

Step1: create a new project

Create->file->new project

Step2:content of main activity file

Src/com.exmaple.tutorialspoint/main activity.java

Step3:cotent of

res/layout/activity main.xml file

Step4: content of

Res/values/strings.xml to define constraints

Step5: content of manifest xml file

Android manifext.xml

Step6: run the app from android studio (actual mobile device is connected from computer)
1701109

Click RUN from any projects activity files to see the output.

Step7: click on SEND SMS to send your sms.

Existing SMS client to send SMS:

Method 1: using built-in intent to send sms

Method 2: using intent object-action to send sms

Method3: using intent object-data/type to send sms

Method4: using intent object- extra to send sms

SOURCE CODE:

Code for src/com.example.tutorialspoint/MainActivity.java.

package com.example.tutorialspoint;

import android.Manifest;

import android.content.pm.PackageManager;

import android.os.Bundle;

import android.app.Activity;

import android.support.v4.app.ActivityCompat;

import android.support.v4.content.ContextCompat;

import android.telephony.SmsManager;

import android.util.Log;

import android.view.Menu;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends Activity {

private static final int MY_PERMISSIONS_REQUEST_SEND_SMS =0 ;

Button sendBtn;

EditText txtphoneNo;
1701109

EditText txtMessage;

String phoneNo;

String message;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

sendBtn = (Button) findViewById(R.id.btnSendSMS);

txtphoneNo = (EditText) findViewById(R.id.editText);

txtMessage = (EditText) findViewById(R.id.editText2);

sendBtn.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

sendSMSMessage();

});

} protected void sendSMSMessage() {

phoneNo = txtphoneNo.getText().toString();

message = txtMessage.getText().toString();

if (ContextCompat.checkSelfPermission(this,

Manifest.permission.SEND_SMS)

!= PackageManager.PERMISSION_GRANTED) {

if (ActivityCompat.shouldShowRequestPermissionRationale(this,

Manifest.permission.SEND_SMS)) {

} else {

ActivityCompat.requestPermissions(this,

new String[]{Manifest.permission.SEND_SMS},

MY_PERMISSIONS_REQUEST_SEND_SMS);}}}
1701109

@Override

public void onRequestPermissionsResult(int requestCode,String permissions[], int[]


grantResults) {

switch (requestCode) {

case MY_PERMISSIONS_REQUEST_SEND_SMS: {

if (grantResults.length > 0

&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage(phoneNo, null, message, null, null);

Toast.makeText(getApplicationContext(), "SMS sent.",

Toast.LENGTH_LONG).show();

} else {

Toast.makeText(getApplicationContext(),

"SMS faild, please try again.", Toast.LENGTH_LONG).show();

return;}}}}}

code for res/layout/activity_main.xml file

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

<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:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="MainActivity">
1701109

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Sending SMS Example"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:textSize="30dp" />

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Tutorials point "

android:textColor="#ff87ff09"

android:textSize="30dp"

android:layout_below="@+id/textView1"

android:layout_alignRight="@+id/imageButton"

android:layout_alignEnd="@+id/imageButton" />

<ImageButton

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/imageButton"

android:src="@drawable/abc"

android:layout_below="@+id/textView2"

android:layout_centerHorizontal="true" />

<EditText

android:layout_width="wrap_content"
1701109

android:layout_height="wrap_content"

android:id="@+id/editText"

android:hint="Enter Phone Number"

android:phoneNumber="true"

android:textColorHint="@color/abc_primary_text_material_dark"

android:layout_below="@+id/imageButton"

android:layout_centerHorizontal="true" />

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/editText2"

android:layout_below="@+id/editText"

android:layout_alignLeft="@+id/editText"

android:layout_alignStart="@+id/editText"

android:textColorHint="@color/abc_primary_text_material_dark"

android:layout_alignRight="@+id/imageButton"

android:layout_alignEnd="@+id/imageButton"

android:hint="Enter SMS" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Send Sms"

android:id="@+id/btnSendSMS"

android:layout_below="@+id/editText2"

android:layout_centerHorizontal="true"

android:layout_marginTop="48dp" />

</RelativeLayout>
1701109

Code for res/values/strings.xml to define two new constants

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

<resources>

<string name="app_name">tutorialspoint</string>

</resources>

Code for AndroidManifest.xml

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.tutorialspoint" >

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

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme"

<activity

android:name="com.example.tutorialspoint.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter></activity></application></manifest>
1701109

OUTPUT:

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2
TOTAL 20

RESULT:

Thus an android app was developed to send user sms and receive reply. The output was
displayed successfully.
1701109

EXNO 15

DATE: DEVELOP A PROGRAM TO CONVERT TEXT TO SPEECH


13.3.20

AIM:

To develop an android app to convert text to speech and to display the output.

PROCEDURE:

Step1: android provides TEXT TO SPEECH class to instantiates an object of thos class with
specification init listener.

Step2: specify the properties for TEXT TO SPEECH object. Language can be set by calling
set language () method.

Step3: After language setup, call speak () method of the class to speak the text.

Functions available in TEXT TO SPEECH class:

1) Add speech(string text, string file name)


2) Get language()
3) Is speaking()
4) Set pitch(float pitch())
5) Set speech rate(float speech rate())
6) Shutdown()
7) Stop()

PROGRAM PROCEDURE:

Step1: content of src main activity.java

Step2: content of activity main.xml

Step3: content of strings.xml

Step4: content of android manifest.xml

Step5: run the app from android studio (actual android mobile device is connected with the
computer)

Click RUN from any projects activity file to see the output.

Step6: after checking the output display screen, type some text field, click on TEXT TO
SPEECH button .a notification would appear and text will be spoken. Do at different location
and you will hear the sound.
1701109

SOURCE CODE:

Code to src/MainActivity.java.

package com.example.sairamkrishna.myapplication;

import android.app.Activity;

import android.os.Bundle;

import android.speech.tts.TextToSpeech;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import java.util.Locale;

import android.widget.Toast;

public class MainActivity extends Activity {

TextToSpeech t1;

EditText ed1;

Button b1;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

ed1=(EditText)findViewById(R.id.editText);

b1=(Button)findViewById(R.id.button);

t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {

@Override

public void onInit(int status) {

if(status != TextToSpeech.ERROR) {

t1.setLanguage(Locale.UK);

}}});
1701109

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String toSpeak = ed1.getText().toString();

Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();

t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);

}});}

public void onPause(){

if(t1 !=null){

t1.stop();

t1.shutdown();}

super.onPause();}}

code to activity_main.xml

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

<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=".MainActivity"

android:transitionGroup="true">

<TextView android:text="Text to Speech" android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/textview"

android:textSize="35dp"
1701109

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Tutorials point"

android:id="@+id/textView"

android:layout_below="@+id/textview"

android:layout_centerHorizontal="true"

android:textColor="#ff7aff24"

android:textSize="35dp" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/imageView"

android:src="@drawable/abc"

android:layout_below="@+id/textView"

android:layout_centerHorizontal="true"

android:theme="@style/Base.TextAppearance.AppCompat" />

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/editText"

android:layout_below="@+id/imageView"

android:layout_marginTop="46dp"

android:hint="Enter Text"

android:layout_alignParentRight="true"
1701109

android:layout_alignParentEnd="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:textColor="#ff7aff10"

android:textColorHint="#ffff23d1" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Text to Speech"

android:id="@+id/button"

android:layout_below="@+id/editText"

android:layout_centerHorizontal="true"

android:layout_marginTop="46dp" />

</RelativeLayout>

content of Strings.xml.

<resources>

<string name="app_name">My Application</string></resources>.

the content of AndroidManifest.xml

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.sairamkrishna.myapplication" >

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >
1701109

<activity

android:name=".MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" >

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter></activity></application></manifest>

OUTPUT:
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5

PRE LAB PREPARATION 6


IN LAB PERFORMANCE 7
POST VIVA 2
TOTAL 20

RESULT:

Thus an android app was developed to convert text to speech and output was displayed
successfully.
1701109

EXNO 16
DEVELOP A PROGRAM TO CALL A NUMBER
DATE:
20.3.20

AIM:

To develop an android studio to make a phone call a number and to display an output.

PROCEDURE:

1) Intent Object - Action to make Phone Call

use ACTION_CALL action to trigger built-in phone call functionality available in Android
device

syntax to create an intent with ACTION_CALL action

2)Intent phoneIntent = new Intent(Intent.ACTION_CALL);

use ACTION_DIAL action instead of ACTION_CALL, in that case you will have option to
modify hardcoded phone number before making a call instead of making a direct call.

3)Intent Object - Data/Type to make Phone Call

To make a phone call at a given number 91-000-000-0000, you need to specify tel: as URI
using setData() method as follows −

phoneIntent.setData(Uri.parse("tel:91-000-000-0000"));

The interesting point is that, to make a phone call, you do not need to specify any extra data
or data type.

Step1: content of the modified main activity file

Src main activity.java

Step2: content of res layout activity main.xml file

Step3: Content of res values strings.xml to define constants

Step4: content of android manifest.xml

Step5: run the app from android studio(actual android mobile device is connected with the
computer)

Click RUN from any projects file to see the output.

Step6: After step 5, click CALL to make call action.


1701109

SOURCE CODE:

the modified main activity file src/MainActivity.java.

package com.example.saira_000.myapplication;

import android.Manifest;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.net.Uri;

import android.os.Bundle;

import android.support.v4.app.ActivityCompat;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.Button;

public class MainActivity extends AppCompatActivity {

private Button button;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

button = (Button) findViewById(R.id.buttonCall);

button.setOnClickListener(new View.OnClickListener() {

public void onClick(View arg0) {

Intent callIntent = new Intent(Intent.ACTION_CALL);

callIntent.setData(Uri.parse("tel:0377778888"));

if (ActivityCompat.checkSelfPermission(MainActivity.this,

Manifest.permission.CALL_PHONE) !=
PackageManager.PERMISSION_GRANTED) {

return; }
1701109

startActivity(callIntent); }});}}}

the content of res/layout/activity_main.xml file

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<Button

android:id="@+id/buttonCall"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="call 0377778888" />

</LinearLayout>

the content of res/values/strings.xml to define two new constants

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

<resources>

<string name="app_name">My Application</string>

</resources>

the default content of AndroidManifest.xml

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.saira_000.myapplication"

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

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"
1701109

android:theme="@style/AppTheme" >

<activity

android:name="com.example.saira_000.myapplication.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter> </activity></application></manifest>

OUTPUT:
1701109

NOMENCLATURE MAX MARKS


MARKS OBTAINED
PRE VIVA 5
PRE LAB PREPARATION 6
IN LAB PERFORMANCE 7
POST VIVA 2

TOTAL 20

RESULT:

Thus an android app was developed to call a number and output as displayed
successfully.

You might also like