Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 108

PSG POLYTECHNIC COLLEGE

DEPARTMENT OF COMPUTER ENGINEERING

LAB MANUAL

SMART DEVICE PROGRAMMING

Prepared by Verified by

Ms A Haritha Deepthi Ms P Rajeswari

The Head In Charge- DCE

1
S.no Name of the Experiments Page No

1 Develop an application that uses GUI components, Font and Colours. 3

2 Develop an application that uses Layout Managers and event listeners. 11

3 Develop a calculator application. 23

4 Write an application that draws basic graphical primitives on the screen. 49

5 Develop an application that makes use of database. 52

6 Develop an application that makes use of RSS Feed. 63

7 Develop a native application that uses GPS location information. 73

8 Develop an application for speech recognition. 81

9 Implement an application that creates an alert upon receiving a message. 89

10 Develop an android application on any one of the following. 93

● Restaurant Management System


● Home Automation
● Shapes App for special children
● Restaurant Order System
● Student Management System
● App for Educational Institutions
● Android Quiz App
● Friend Tracker
● Attendance Management System
● Beauty Products Ecommerce App

2
Ex No : 1 Develop an Application that uses GUI components, Font and
Colors Date :

Aim:

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

Procedure:

Creating a New project:

▪ Open Android Stdio and then click on File -> New -> New project.
▪ Then type the Application name as “ex.no.1″ and click Next.
▪ Then select the Minimum SDK as shown below and click Next.
▪ Then select the Empty Activity and click Next.
▪ Finally click Finish.
▪ It will take some time to build and load the project.
▪ After completion it will look as given below.

Designing layout for the Android Application:

▪ Click on app -> res -> layout -> activity_main.xml.


▪ Now click on Text as shown below.
▪ Then delete the code which is there and type the code as given below.

3
Code for Activity_main.xml:

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

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/andro
id"

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
android:soundEffectsEnabled="?android:attr/windowOvers
can" tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="314d
p"
android:layout_height="54dp
"

android:text="Type your birth year!!"

android:textAppearance="@style/TextAppearance.Compat.Notific

ation" android:textColor="#000000"

android:textSize="25sp"

android:visibility="visible"

app:fontFamily="@font/cherry_cream_soda

"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.659"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textVie
w3" app:layout_constraintVertical_bias="0.016" />
4
<Button
android:id="@+id/btnSubmit"
android:layout_width="120dp"
android:layout_height="49dp"
android:layout_marginTop="60dp"
android:background="@drawable/custom_butto
n" android:onClick="onSubmit"
android:shadowDx="10"

android:shadowDy="10"

android:shadowRadius="10"

android:text="Submit"

android:textAllCaps="false"

android:textColor="#ffff"

android:textSize="20sp"

android:typeface="sans"

app:layout_constraintEnd_toEndOf="parent

"

app:layout_constraintHorizontal_bias="0.05

4"

app:layout_constraintStart_toStartOf="pare

nt"

app:layout_constraintTop_toBottomOf="@+id/input" />

<EditText

android:id="@+id/input"

android:layout_width="283d

p"

android:layout_height="42dp

"

android:layout_marginTop="40dp"
android:ems="10"

5
android:inputType="textPersonName"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent
"
app:layout_constraintStart_toStartOf="pare
nt"

app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView

android:id="@+id/tvAge"

android:layout_width="98dp"

android:layout_height="29dp

"

android:layout_marginTop="72dp"

android:text="Age: 0"

android:textSize="18sp"

app:fontFamily="@font/cherry_cream_so

da"

app:layout_constraintEnd_toEndOf="pare

nt"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/btnSubmit

" />

<TextView

android:id="@+id/textView3"

android:layout_width="262dp"

android:layout_height="90dp"

android:layout_marginTop="28d

p" android:text="Age App"

android:textColor="#000000"

android:textColorHint="#9C27B
6
0" android:textSize="36sp"

app:fontFamily="@font/bungee_shade"

app:layout_constraintEnd_toEndOf="parent

"

app:layout_constraintHorizontal_bias="0.69

9"

app:layout_constraintStart_toStartOf="pare

nt"

app:layout_constraintTop_toTopOf="parent"

/>

</androidx.constraintlayout.widget.ConstraintLayout>

Java Coding for the Android Application:

▪ Click on app -> java -> com.example.temp -> MainActivity.


▪ Then delete the code which is there and type the code as given below.

Code for MainActivity.java:

package com.example.ageapp

import androidx.appcompat.app.AppCompatActivity

import android.os.Bundle

import android.view.View

import kotlinx.android.synthetic.main.activity_main.*

import java.util.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?)

{ super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

fun onSubmit(view:View){

val currentYear = Calendar.getInstance().get(Calendar.YEAR)

7
tvAge.text = "Age : "+ (currentYear - input.text.toString().toInt())

8
OUTPUT :

9
RESULT :

Thus a Simple Android Application that uses GUI components, Font and Colors is

10
developed and executed successfully.
Ex No : 2 Develop an Application that uses Layout Managers and Event
Listeners

Date :

Aim:

To develop a Simple Android Application that uses Layout Managers and Event Listeners.

Procedure:

Creating a New project:

▪ Open Android Studio and then click on File -> New -> New project.
▪ Then type the Application name as “Corona″ and click Next.
▪ Then select the Minimum SDK as shown below and click Next.
▪ Then select the Empty Activity and click Next.
▪ Finally click Finish.
▪ It will take some time to build and load the project.
▪ After completion it will look as given below.

Creating Second Activity for the Android Application:

▪ Click on File -> New -> Activity -> Empty Activity.


▪ Type the Activity Name as Scan and click Finish button.
▪ Thus Second Activity For the application is created.

Designing Layout for Main Activity:

▪ Click on app -> res -> layout -> activity_main.xml.


▪ Now click on Text as shown below.
▪ Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

11
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_corona"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView3"
android:layout_width="223dp"
android:layout_height="68dp"
android:text="COVID - 19"
android:textColor="#ffffff"
android:textSize="35sp"
app:fontFamily="@font/doppio_one"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.627"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.556" />
<TextView
android:id="@+id/textView"
android:layout_width="217dp"
android:layout_height="47dp"
android:text="STAY HOME"
android:textColor="#ffffff"
android:textSize="30sp"
app:fontFamily="@font/adamina"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

12
app:layout_constraintTop_toBottomOf="@+id/textView3"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="STAY SAFE"
android:textColor="#ffffff"
android:textSize="30sp"
app:fontFamily="@font/adamina"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<ImageButton
android:id="@+id/scan_btn"
android:layout_width="71dp"
android:layout_height="84dp"
android:layout_centerInParent="true"
android:layout_marginBottom="28dp"
android:focusableInTouchMode="false"
android:soundEffectsEnabled="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/stat_btn"
app:layout_constraintHorizontal_bias="0.698"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.941"
app:srcCompat="@drawable/scan" />
<ImageButton
android:id="@+id/stat_btn"
android:layout_width="71dp"
android:layout_height="84dp"

13
android:layout_centerInParent="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="28dp"
android:focusableInTouchMode="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/prevention_btn
" app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.941"
app:srcCompat="@drawable/statics" />
<ImageButton
android:id="@+id/prevention_btn"
android:layout_width="71dp"
android:layout_height="84dp"
android:layout_centerInParent="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="28dp"
android:focusableInTouchMode="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/symptoms_btn"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.941"
app:srcCompat="@drawable/prevention" />
<ImageButton
android:id="@+id/symptoms_btn"
android:layout_width="71dp"
android:layout_height="84dp"
android:layout_centerInParent="true"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="28dp"
android:focusableInTouchMode="false"

14
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.941"
app:srcCompat="@drawable/symptoms" />
</androidx.constraintlayout.widget.ConstraintLayout>

Designing Layout for Second Activity:

▪ Click on app -> res -> layout -> activity_scan.xml.


▪ Now click on Text as shown below.
▪ Then delete the code which is there and type the code as given below.

Code for activity_scan.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="16dp"
android:background="@drawable/scan_bg_e"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:weightSum="10" tools:context=".Scan">
<ImageView android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="643dp"
android:layout_weight="9" />
<Button
android:id="@+id/btnCamera"

15
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#121212"
android:textColor="#ffff" />
<ImageButton
android:id="@+id/back_btn"
android:layout_width="56dp"
android:layout_height="55dp"
android:layout_weight="9"
app:srcCompat="@drawable/back_btn" />
</LinearLayout>

Java Coding for the Android Application:

Java Coidng for Main Activity:

▪ Click on app -> java -> com.example.temp2 -> MainActivity.


▪ Then delete the code which is there and type the code as given below.

Code for MainActivity.java:


package com.example.corona;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.os.Bundle;

import android.os.Vibrator;

import android.view.View;

import android.widget.ImageButton;

public class MainActivity extends AppCompatActivity {

private ImageButton scan_btn;

private ImageButton stat_btn;

16
private ImageButton prevention_btn;

private ImageButton symptoms_btn;

Vibrator vibrator1;

Vibrator vibrator2;

Vibrator vibrator3;

Vibrator vibrator4;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

scan_btn = (ImageButton) findViewById(R.id.scan_btn);

vibrator1 = (Vibrator)getSystemService(VIBRATOR_SERVICE);

scan_btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v1)

{ vibrator1.vibrate(30);

scanActivity();

});

stat_btn = (ImageButton) findViewById(R.id.stat_btn);

vibrator2 = (Vibrator)getSystemService(VIBRATOR_SERVICE);

stat_btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v1)

{ vibrator2.vibrate(30);

statActivity();

17
}

});

prevention_btn = (ImageButton) findViewById(R.id.prevention_btn);

vibrator3 = (Vibrator)getSystemService(VIBRATOR_SERVICE);

prevention_btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v1)

{ vibrator3.vibrate( 30);

preventionActivity();

});

symptoms_btn = (ImageButton) findViewById(R.id.symptoms_btn);

vibrator4 = (Vibrator)getSystemService(VIBRATOR_SERVICE);

symptoms_btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v1)

{ vibrator4.vibrate(30);

symptomsActivity();

});

public void scanActivity(){

Intent activity1 = new Intent(this, Scan.class );

startActivity(activity1);

public void statActivity(){


18
Intent activity2 = new Intent(this, Statistics.class );

startActivity(activity2);

}public void preventionActivity(){

Intent activity3 = new Intent(this, Prevention.class );

startActivity(activity3);

}public void symptomsActivity(){

Intent activity4 = new Intent(this, Symptoms.class );

startActivity(activity4);

Java Coding for MainActivity2:

▪ Click on app -> java -> com.example.temp2 -> Scan.


▪ Then delete the code which is there and type the code as given below.

Code for Scan.java:


package com.example.corona;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button; import
android.widget.ImageButton; import
android.widget.ImageView;
public class Scan extends AppCompatActivity { ImageView
imageView;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);

19
setContentView(R.layout.activity_scan);
ImageButton back_btn = (ImageButton) findViewById(R.id.back_btn);
back_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v1)
{ backActivity();
}
});
Button btncamera = (Button) findViewById(R.id.btnCamera); ImageView
imageview = (ImageView) findViewById(R.id.imageView);
btncamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{ super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
public void backActivity(){
Intent main = new Intent(this,MainActivity.class );
startActivity(main);
}
}

20
OUTPUT:

21
Result:

Thus a Simple Android Application that uses Layout Managers and Event Listeners is
developed and executed successfully.

22
Ex No : 3 Develop a Calculator
Application Date :
Aim:

To develop a calculator application

Procedure:

Creating a New project:

▪ Open Android Studio and then click on File -> New -> New project.
▪ Then type the Application name as “ex.no.3″ and click Next.
▪ Then select the Minimum SDK as shown below and click Next.
▪ Then select the Empty Activity and click Next.
▪ Finally click Finish.
▪ It will take some time to build and load the project.
▪ After completion it will look as given below.

Designing layout for the Android Application:

▪ Click on app -> res -> layout -> activity_main.xml.


▪ Now click on Text as shown below.
▪ Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

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

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

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

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<Button

android:id="@+id/btnmul"

23
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="*"

app:layout_constraintStart_toEndOf="@+id/

btn4"

app:layout_constraintTop_toBottomOf="@+id/btndiv" />

<Button

android:id="@+id/btn9"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentBottom="true"

android:layout_centerVertical="true"

android:layout_marginTop="32dp"

android:text="9"

app:layout_constraintStart_toStartOf="paren

t"

app:layout_constraintTop_toBottomOf="@+id/btninfo" />

<Button

android:id="@+id/btn8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
24
android:layout_alignParentStart="true"

25
android:layout_alignParentBottom="true"

android:layout_centerVertical="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="8"

app:layout_constraintStart_toEndOf="@+id/

btn9"

app:layout_constraintTop_toBottomOf="@+id/btninfo" />

<Button

android:id="@+id/btndiv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_alignParentEnd="true"

android:layout_centerVertical="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="/"

app:layout_constraintStart_toEndOf="@+id/

btn7"

app:layout_constraintTop_toBottomOf="@+id/btninfo" />

<Button

android:id="@+id/btn7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

26
android:layout_alignParentStart="true"

27
android:layout_alignParentTop="true"

android:layout_centerVertical="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="7"

app:layout_constraintStart_toEndOf="@+id/

btn8"

app:layout_constraintTop_toBottomOf="@+id/btninfo" />

<Button

android:id="@+id/btn6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentBottom="true"

android:layout_marginTop="32dp"

android:text="6"

app:layout_constraintStart_toStartOf="paren

t"

app:layout_constraintTop_toBottomOf="@+id/btn9" />

<Button

android:id="@+id/btn5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentBottom="true"

android:layout_marginStart="20dp"
28
android:layout_marginTop="32dp"

29
android:text="5"

app:layout_constraintStart_toEndOf="@+id/btn6"

app:layout_constraintTop_toBottomOf="@+id/btn8" />

<Button

android:id="@+id/btn4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="4"

app:layout_constraintStart_toEndOf="@+id/

btn5"

app:layout_constraintTop_toBottomOf="@+id/btn7" />

<Button

android:id="@+id/btn3"

android:layout_width="wrap_content"

android:layout_height="48dp"

android:layout_alignParentStart="true"

android:layout_alignParentBottom="true"

android:layout_marginTop="32dp"

android:text="3"

app:layout_constraintStart_toStartOf="paren

t"

app:layout_constraintTop_toBottomOf="@+id/btn6" />
30
<Button

android:id="@+id/btn2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentBottom="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="2"

app:layout_constraintStart_toEndOf="@+id/

btn3"

app:layout_constraintTop_toBottomOf="@+id/btn5" />

<Button

android:id="@+id/btn1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="1"

app:layout_constraintStart_toEndOf="@+id/

btn2"

app:layout_constraintTop_toBottomOf="@+id/btn4" />

<Button

android:id="@+id/btnadd"
31
android:layout_width="wrap_content"

32
android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="+"

app:layout_constraintStart_toEndOf="@+id/

btn1"

app:layout_constraintTop_toBottomOf="@+id/btnmul" />

<Button

android:id="@+id/btnclr"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentBottom="true"

android:layout_marginTop="32dp"

android:text="CLEAR"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/btn3

" />

<Button

android:id="@+id/btn0"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentBottom="true"
33
android:layout_marginStart="20dp"

34
android:layout_marginTop="32dp"

android:text="0"

app:layout_constraintStart_toEndOf="@+id/b

tnclr"

app:layout_constraintTop_toBottomOf="@+id/btn2" />

<Button

android:id="@+id/btnequ

al"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="="

app:layout_constraintStart_toEndOf="@+id/

btn0"

app:layout_constraintTop_toBottomOf="@+id/btn1" />

<Button

android:id="@+id/btnmin"

android:layout_width="wrap_content"

android:layout_height="wrap_content

"

android:layout_alignParentEnd="true

"

android:layout_alignParentBottom="t
35
rue"

android:layout_marginStart="20dp"

android:layout_marginTop="32dp"

android:text="-"

app:layout_constraintStart_toEndOf="@+id/btnequal"

36
app:layout_constraintTop_toBottomOf="@+id/btnadd" />

<TextView

android:id="@+id/btninfo"

android:layout_width="382dp"

android:layout_height="301dp

"

android:layout_alignParentStart="true"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="4dp"

android:layout_marginEnd="19dp"

android:scrollbars="vertical"

android:textAlignment="textEnd"

android:textSize="36sp"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.8"

app:layout_constraintStart_toStartOf="paren

t"

app:layout_constraintTop_toTopOf="parent"

/>

<TextView

android:id="@+id/btnchodu"

android:layout_width="63dp"

android:layout_height="4dp"

android:layout_alignParentEnd="true"

android:layout_alignParentBottom="true"
37
android:layout_marginTop="132dp"

android:layout_marginEnd="66dp"

38
android:visibility="invisible"

app:layout_constraintEnd_toStartOf="@+id/btninfo"

app:layout_constraintHorizontal_bias="0.0"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Java Coding for the Android Application:

▪ Click on app -> java -> com.example.exno3 -> MainActivity.


▪ Then delete the code which is there and type the code as given below.

Code for MainActivity for java:

//Main file with code

package com.example.calculator;

import

android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import

android.widget.TextView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

39
private Button one;

private Button two;

private Button three;

private Button four;

private Button five;

private Button six;

private Button seven;

private Button eight;

private Button nine;

private Button zero;

private Button add;

private Button mul;

private Button equals;

private Button clr;

private Button sub;

private Button div;

private TextView info;

private TextView

chodu;

private double

val1=Double.NaN; private char

val2 ='+';

private double res

=0; private int i=1;

private int p=1;

@Override

protected void

onCreate(Bundle
40
savedInstanceState

){

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

setupUIViews();
zero.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

info.setText(info.getText().toString()+"0");

chodu.setText(chodu.getText().toString()+"0");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

});

clr.setOnClickListener(new

View.OnClickListener() { @Override

41
public void onClick(View

v) { info.setText("");

chodu.setText(""

); res=0;

val1=Double.Na

N; val2='+';

i=1;

});

equals.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(!

Double.isNaN(val1)){

compute();

info.setText(""+res);

chodu.setText(""+res);

//res=0;

val1=Double.Na

N;

i=1;

val2='+'

; p=0;}

else{

info.setText(""+res);

chodu.setText(""+re

s); p=0;
42
}

});
one.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

info.setText(info.getText().toString()+"1");

chodu.setText(chodu.getText().toString()+"1");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

});
two.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1)

{info.setText("");

43
chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

info.setText(info.getText().toString()+"2");

chodu.setText(chodu.getText().toString()+"2");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

});

three.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

44
}

info.setText(info.getText().toString()+"3");

chodu.setText(chodu.getText().toString()+"3");

val1=

Double.parseDouble(chodu.getText().toString());

i=1;

});

four.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

info.setText(info.getText().toString()+"4");

chodu.setText(chodu.getText().toString()+"4");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

45
});

five.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

info.setText(info.getText().toString()+"5");

chodu.setText(chodu.getText().toString()

+"5");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

});

six.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");
46
chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

info.setText(info.getText().toString()+"6");
chodu.setText(chodu.getText().toString()+"6");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

});

seven.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

47
}

info.setText(info.getText().toString()+"7");

chodu.setText(chodu.getText().toString()+"7");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

});

eight.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View v) {


if(p!=1)

{ info.setText("

");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

info.setText(info.getText().toString()+"8");

chodu.setText(chodu.getText().toString()+"8");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

}
48
});

nine.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

}
info.setText(info.getText().toString()+"9");

chodu.setText(chodu.getText().toString()+"9");

val1 =

Double.parseDouble(chodu.getText().toString());

i=1;

});

add.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""
49
);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

if(i!=0) {

info.setText(info.getText().toString() + "+");

chodu.setText("");

compute()

; val2 =

'+'; i=0;

}
});

sub.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;
50
}

if(i!=0)

{ info.setText(info.getText().toString()

+"-"); chodu.setText("");

compute()

; val2='-';

i=0;

}}

});

mul.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");
chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

if(i!=0)

{ info.setText(info.getText().toString()

+"*"); chodu.setText("");

compute()

; val2='*';

i=0;
51
}}

});

div.setOnClickListener(new

View.OnClickListener() { @Override

public void onClick(View

v) { if(p!=1){

info.setText("");

chodu.setText(""

);

val1=Double.Na

N; val2 ='+';

res

=0;

p=1;

}
if(i!=0)

{ info.setText(info.getText().toString()

+"/"); chodu.setText("");

compute()

; val2='/';

i=0;

}}

});

private void setupUIViews(){

52
one =

(Button)findViewById(R.id.btn1); two

= (Button)findViewById(R.id.btn2);

three =

(Button)findViewById(R.id.btn3); four

= (Button)findViewById(R.id.btn4);

five =

(Button)findViewById(R.id.btn5); six =

(Button)findViewById(R.id.btn6);

seven =

(Button)findViewById(R.id.btn7); eight

= (Button)findViewById(R.id.btn8);

nine =

(Button)findViewById(R.id.btn9); zero

= (Button)findViewById(R.id.btn0);

add =

(Button)findViewById(R.id.btnadd);

sub =

(Button)findViewById(R.id.btnmin);

mul =

(Button)findViewById(R.id.btnmul); div

= (Button)findViewById(R.id.btndiv);

53
info = (TextView)findViewById(R.id.btninfo);

clr = (Button)findViewById(R.id.btnclr);

equals = (Button)findViewById(R.id.btnequal);

chodu =

(TextView)findViewById(R.id.btnchodu);

private void compute(){ if(!

Double.isNaN(val1)){

if(val2=='+')

{ res=res+val1;

val1=Double.NaN;

if(val2=='-')

{ res=res-val1;

val1=Double.NaN;

if(val2=='*')

{ res=res*val1;

val1=Double.NaN;

if(val2=='/'){

res=res/val1;

val1=Double.NaN;

}}
}

54
OUTPUT :

Result:

Thus a Simple Android Application for Calculator is developed and executed successfully.

55
Ex No : 4 Write an application that draws basic graphical primitives on the screen.

Date:

Aim:

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

Procedure:
Creating a New project:

▪ Open Android Studio and then click on File -> New -> New project.
▪ Then type the Application name as “Graphicalprimitives″ and click Next.
▪ Then select the Minimum SDK as shown below and click Next.
▪ Then select the Empty Activity and click Next.
▪ Finally click Finish.
▪ It will take some time to build and load the project.
▪ After completion it will look as given below.

Designing layout for the Android Application:

▪ Click on app -> res -> layout -> activity_main.xml.


▪ Now click on Text as shown below.
▪ Then delete the code which is there and type the code as given below.

Code for Activity_main.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"

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

</RelativeLayout>

Java Coding for the Android Application:

▪ Click on app -> java -> com.example.temp5 -> MainActivity.


▪ Then delete the code which is there and type the code as given below.

Code for MainActivity.java

package com.example.graphicalprimitives;

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

Bitmap bg = Bitmap.createBitmap(720, 1280,

Bitmap.Config.ARGB_8888);

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

i.setBackgroundDrawable(new BitmapDrawable(bg));

Canvas canvas = new Canvas(bg);

Paint paint = new Paint();

57
paint.setColor(Color.BLUE);

paint.setTextSize(50);

canvas.drawText("Rectangle", 420, 150, paint);

canvas.drawRect(400, 200, 650, 700, paint);

canvas.drawText("Circle", 120, 150, paint);

canvas.drawCircle(200, 350, 150, paint);

canvas.drawText("Square", 120, 800, paint);

canvas.drawRect(50, 850, 350, 1150, paint);

canvas.drawText("Line", 480, 800, paint);

canvas.drawLine(520, 850, 520, 1150, paint);

OUTPUT:

Result:

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

58
Ex No: 5 Develop an application that make use of
database Date:

Aim:
To develop an application that make use of database.

Aim :

To develop an application for making use of the database .

Procedure:

Creating a New project:


● Open Android Studio and then click on File -> New -> New project.
● Then type the Application name as “ex.no.5″ and click Next.
● Then select the Minimum SDK as shown below and click Next.
● Then select the Empty Activity and click Next.
● Finally click Finish.
● It will take some time to build and load the project.
● After completion it will look as given below.
Designing layout for the Android Application:
● Click on app -> res -> layout -> activity_Register.xml.
● Now click on Text as shown below.
● Then delete the code which is there and type the code as given below.

Code for 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"

59
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="development.assistant.project.s_assistant.noteActivit
y">
<ListView
android:id="@+id/noteLi
st"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
<android.support.design.widget.FloatingActionB
utton android:id="@+id/fab_Note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="bottom"
android:clickable="true"
android:elevation="5dp"
android:src="@drawable/ic_content_add_circl
e" app:backgroundTint="@color/colorPrimary"
app:borderWidth="0dp" />
</RelativeLayout>

Code for Activity_Register.xml:


<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/androi
d"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/loginbg"
60
tools:context=".Register">

<EditText
android:id="@+id/password"
android:layout_width="337dp"
android:layout_height="41dp"
android:background="#FFFFF
F" android:ems="10"
android:fontFamily="@font/aclonica"
android:hint="Password"
android:inputType="textPersonName"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView
3" app:layout_constraintVertical_bias="0.32999998" />

<EditText
android:id="@+id/fullname"
android:layout_width="337dp"
android:layout_height="41dp"
android:background="#FFFFF
F" android:ems="10"
android:fontFamily="@font/aclonica"
android:hint=" Full Name"
android:inputType="textPersonName"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="p
arent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent
"
app:layout_constraintTop_toBottomOf="@+id/
textView3"
61
app:layout_constraintVertical_bias="0.100000024" />

<EditText
android:id="@+id/confirmpassword"
android:layout_width="337dp"
android:layout_height="41dp"
android:background="#FFFFFF"
android:ems="10"
android:fontFamily="@font/aclonica"
android:hint=" Confirm Password"
android:inputType="textPersonName"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView
3" app:layout_constraintVertical_bias="0.45" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_cont
ent"
android:layout_height="wrap_content"
android:fontFamily="@font/aclonica"
android:text="PinMe"
android:textColor="@android:color/background_l
ight" android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="paren
t" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.11000001
4" />

<TextView
android:id="@+id/textView3"
62
android:layout_width="wrap_cont
ent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:fontFamily="@font/aclonica"
android:text="Create a New Account"
android:textColor="@android:color/background_l
ight" android:textSize="25sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />

<EditText
android:id="@+id/email"
android:layout_width="337
dp"
android:layout_height="41d
p"
android:background="#FFFFFF"
android:ems="10"
android:fontFamily="@font/aclonica"
android:hint=" Email"
android:inputType="textPersonName"
android:textSize="20sp"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView
3" app:layout_constraintVertical_bias="0.22000003" />

<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarSt
yle"

63
android:layout_width="wrap_conte
nt"
android:layout_height="wrap_cont
ent"
android:layout_marginBottom="80
dp" android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<TextView
android:id="@+id/createbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="64dp"
android:fontFamily="@font/aclonica"
android:text="Already have a Account? Login
here.
"
android:textColor="#FFFFFF"
android:textSize="15sp"
app:layout_constraintBottom_toTopOf="@+id/
progressBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginbutt
on" app:layout_constraintVertical_bias="0.922" />

<Button
android:id="@+id/
registerbtn"
android:layout_width="336
dp"
android:layout_height="57
dp" android:text="Register"

64
app:layout_constraintBottom_toTopOf="@+id/createbtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/confirmpassword" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java Coding for the Android Application:


● Click on app -> java -> com.example.exno1 ->Register.
● Then delete the code which is there and type the code as given below.

Code forMainActivity.java:
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Code for Register.java:
package com.example.pinmeapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import
android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import

65
android.widget.Button;
import
android.widget.EditText;
import
android.widget.ProgressBar;
import android.widget.TextView;

import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import
com.google.firebase.auth.AuthResult;
import
com.google.firebase.auth.FirebaseAuth;

public class Register extends AppCompatActivity {


EditText mFullName , mEmail , mPassword ,
mConfirmPassword; Button mRegisterButton;
TextView
mLoginButton;
FirebaseAuth fAuth;
ProgressBar
progressbar;

@Override
protected void onCreate(Bundle
savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);

mFullName =
findViewById(R.id.fullname); mEmail =
findViewById(R.id.email); mPassword =
findViewById(R.id.password);
mConfirmPassword =

66
findViewById(R.id.confirmpassword); mRegisterButton
= findViewById(R.id.registerbtn); mLoginButton =
findViewById(R.id.createbtn);

fAuth = FirebaseAuth.getInstance();
progressbar =
findViewById(R.id.progressBar);

if(fAuth.getCurrentUser() != null){
startActivity(new Intent(getApplicationContext(),MainActivity.class));
finish();
}

mRegisterButton.setOnClickListener(new
View.OnClickListener() { @Override
public void onClick(View v){
String email = mEmail.getText().toString().trim();
String password = mPassword.getText().toString().trim();

if(TextUtils.isEmpty(email))
{ mEmail.setError("Email is
Required."); return;
}

if(TextUtils.isEmpty(password))
{ mPassword.setError("Password is
Required."); return;
}

if(password.length() < 6){


mPassword.setError("Password must be greater than 6
characters"); return;
}

progressbar.setVisibility(View.VISIBLE);

67
fAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new
OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult>
task) { if(task.isSuccessful()){
Toast.makeText(Register.this , "User Created."
,Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),MainActivity.class));
}
else {
Toast.makeText(Register.this ,
"ERROR!!!!"+task.getException().getMessage() , Toast.LENGTH_SHORT).show();
progressBar.setVisibility(View.GONE);
}
}
});
}
}
);
mLoginButton.setOnClickListener(new
View.OnClickListener() { @Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(),Login.class));
}
});
}
}

68
OUTPUT:

RESULT:
Thus an application that make use of database was developed and executed
successfully.

69
Ex No: 6 Develop an application that make use of RSS Feed
Date:

Aim:
To develop an application that make use of RSS Feed.

Procedure:

Creating a New project:


⮚ Open Android Studio and then click on File -> New -> New project.
⮚ Then type the Application name as “ex.no.6″ and click Next. 
⮚ Then select the Minimum SDK as shown below and click Next.
⮚ Then select the Empty Activity and click Next. 
⮚ Finally click Finish.
⮚ It will take some time to build and load the project.
⮚ After completion it will look as given below.
Designing layout for the Android Application:
⮚ Click on app -> res -> layout -> activity_main.xml.
⮚ Now click on Text as shown below.
⮚ Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_corona"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView3"

70
android:layout_width="223dp"
android:layout_height="68dp"
android:text="COVID - 19"
android:textColor="#ffffff"
android:textSize="35sp"
app:fontFamily="@font/doppio_one"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.627"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.556" />
<TextView
android:id="@+id/textView"
android:layout_width="217dp"
android:layout_height="47dp"
android:text="STAY HOME"
android:textColor="#ffffff"
android:textSize="30sp"
app:fontFamily="@font/adamina"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/textView3"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="STAY SAFE"
android:textColor="#ffffff"

71
android:textSize="30sp"
app:fontFamily="@font/adamina"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
<ImageButton
android:id="@+id/scan_btn"
android:layout_width="71dp"
android:layout_height="84dp"
android:layout_centerInParent="true"
android:layout_marginBottom="28dp"
android:focusableInTouchMode="false"
android:soundEffectsEnabled="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/stat_btn"
app:layout_constraintHorizontal_bias="0.698"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.941"
app:srcCompat="@drawable/scan" />
<ImageButton
android:id="@+id/stat_btn"
android:layout_width="71dp"
android:layout_height="84dp"

android:layout_centerInParent="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="28dp"
android:focusableInTouchMode="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/prevention_btn"
app:layout_constraintTop_toBottomOf="@+id/textView2"

72
app:layout_constraintVertical_bias="0.941"
app:srcCompat="@drawable/statics" />
<ImageButton
android:id="@+id/prevention_btn"
android:layout_width="71dp"
android:layout_height="84dp"
android:layout_centerInParent="true"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="28dp"
android:focusableInTouchMode="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/symptoms_btn"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.941"
app:srcCompat="@drawable/prevention" />
<ImageButton
android:id="@+id/symptoms_btn"
android:layout_width="71dp"
android:layout_height="84dp"
android:layout_centerInParent="true"
android:layout_marginEnd="40dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="28dp"
android:focusableInTouchMode="false"

app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.941"
app:srcCompat="@drawable/symptoms" />
</androidx.constraintlayout.widget.ConstraintLayout>
Designing Layout for Second Activity:
 Click on app -> res -> layout -> activity_scan.xml.

73
 Now click on Text as shown below.
 Then delete the code which is there and type the code as given below.
Code for activity_scan.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="16dp"
android:background="@drawable/scan_bg_e"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:weightSum="10"
tools:context=".Scan">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="643dp"
android:layout_weight="9" />
<Button
android:id="@+id/btnCamera"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#121212"
android:textColor="#ffff" />
<ImageButton
android:id="@+id/back_btn"
android:layout_width="56dp"
android:layout_height="55dp"

74
android:layout_weight="9"
app:srcCompat="@drawable/back_btn" />
</LinearLayout>
Java Coding for the Android Application:
⮚ Click on app -> java -> com.example.exno6 -> MainActivity.
⮚ Then delete the code which is there and type the code as given below.

Code for MainActivity.java:


package com.example.corona;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.ImageButton;
public class MainActivity extends AppCompatActivity {
private ImageButton scan_btn;
private ImageButton stat_btn;

private ImageButton prevention_btn;


private ImageButton symptoms_btn;
Vibrator vibrator1;
Vibrator vibrator2;
Vibrator vibrator3;
Vibrator vibrator4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scan_btn = (ImageButton) findViewById(R.id.scan_btn);
vibrator1 = (Vibrator)getSystemService(VIBRATOR_SERVICE);
scan_btn.setOnClickListener(new View.OnClickListener() {
@Override

75
public void onClick(View v1) {
vibrator1.vibrate(30);
scanActivity();
}
});
stat_btn = (ImageButton) findViewById(R.id.stat_btn);
vibrator2 = (Vibrator)getSystemService(VIBRATOR_SERVICE);
stat_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v1) {
vibrator2.vibrate(30);
statActivity();

}
});
prevention_btn = (ImageButton) findViewById(R.id.prevention_btn);
vibrator3 = (Vibrator)getSystemService(VIBRATOR_SERVICE);
prevention_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v1) {
vibrator3.vibrate( 30);
preventionActivity();
}
});
symptoms_btn = (ImageButton) findViewById(R.id.symptoms_btn);
vibrator4 = (Vibrator)getSystemService(VIBRATOR_SERVICE);
symptoms_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v1) {
vibrator4.vibrate(30);
symptomsActivity();
}
});
}

76
public void scanActivity(){
Intent activity1 = new Intent(this, Scan.class );
startActivity(activity1);
}
public void statActivity(){

Intent activity2 = new Intent(this, Statistics.class );


startActivity(activity2);
}public void preventionActivity(){
Intent activity3 = new Intent(this, Prevention.class );
startActivity(activity3);
}public void symptomsActivity(){
Intent activity4 = new Intent(this, Symptoms.class );
startActivity(activity4);
}
}
Java Coding for MainActivity2:

 Click on app -> java -> com.example.temp2 -> Scan.


 Then delete the code which is there and type the code as given below.

Code for Scan.java:


package com.example.corona;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class Scan extends AppCompatActivity {
ImageView imageView;

77
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_scan);
ImageButton back_btn = (ImageButton) findViewById(R.id.back_btn);
back_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v1) {
backActivity();
}
});
Button btncamera = (Button) findViewById(R.id.btnCamera);
ImageView imageview = (ImageView) findViewById(R.id.imageView);
btncamera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
public void backActivity(){
Intent main = new Intent(this,MainActivity.class );
startActivity(main);
}
}

78
OUTPUT:

RESULT:
Thus an application that make use of RSS Feed was developed and executed

79
successfully.
Ex No: 7 Develop a native application that uses GPS location information
Date:

Aim:
To develop anative application that uses GPS location information.

Procedure:

Creating a New project:


⮚ Open Android Studio and then click on File -> New -> New project.
⮚ Then type the Application name as “ex.no.7″ and click Next. 
⮚ Then select the Minimum SDK as shown below and click Next.
⮚ Then select the Empty Activity and click Next. 
⮚ Finally click Finish.
⮚ It will take some time to build and load the project.
⮚ After completion it will look as given below.
Designing layout for the Android Application:
⮚ Click on app -> res -> layout -> activity_main.xml.
⮚ Now click on Text as shown below.
⮚ Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:
<?xml version = "1.0" encoding = "utf-8"?>
<LinearLayoutxmlns: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/button"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:text = "getlocation"/>
</LinearLayout>

80
Java Coding for the Android Application:
⮚ Open build.gradle file and add “useLibrary 'android.test.mock' “ in android block.
⮚ Click on app -> java -> com.example.exno7 ->MainActivity.
⮚ Then delete the code which is there and type the code as given below.

Code for MainActivity.java:


Package com.example.ttemp;

Import android.Manifest;
Import android.app.Activity;
Import android.os.Bundle;
Import android.test.mock.MockPackageManager;
Import android.view.View;
Import android.widget.Button;
Import android.widget.Toast;
import androidx.core.app.ActivityCompat;

public class MainActivity extends Activity {

Button btnShowLocation;
private static final int REQUEST_CODE_PERMISSION = 2;
String mPermission = Manifest.permission.ACCESS_FINE_LOCATION;
GPSTrackergps;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

try {
if (ActivityCompat.checkSelfPermission(this, mPermission)!=
MockPackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]

81
{mPermission},REQUEST_CODE_PERMISSION);
}
} catch (Exception e) {
e.printStackTrace();
}

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


btnShowLocation.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
gps = new GPSTracker(MainActivity.this);
if(gps.canGetLocation()){

double latitude = gps.getLatitude();


double longitude = gps.getLongitude();
Toast.makeText(getApplicationContext(), "Your Location is - \nLat: "
+ latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
}else{
gps.showSettingsAlert();
}
}
});
}
}
Java Coding for the Android Application:
⮚ Create java file app -> java -> com.example.exno7 ->GPSTracker.
⮚ Then type the code as given below.

Code for GPSTracker.java:


Package com.example.ttemp;

Import android.app.AlertDialog;
Import android.app.Service;

82
Import android.content.Context;
Import android.content.DialogInterface;
Import android.content.Intent;
Import android.location.Location;
Import android.location.LocationListener;
Import android.location.LocationManager;
Import android.os.Bundle;
Import android.os.IBinder;
Import android.provider.Settings;
Import android.util.Log;

public class GPSTracker extends Service implements LocationListener {

private final Context mContext;

booleanisGPSEnabled = false;
booleanisNetworkEnabled = false;
booleancanGetLocation = false;

Location location;
double latitude;
double longitude;

private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10;


private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1;
protectedLocationManagerlocationManager;

publicGPSTracker(Context context) {
this.mContext = context;
getLocation();
}

public Location getLocation() {


try {

83
locationManager = (LocationManager)
mContext.getSystemService(LOCATION_SERVICE);
isGPSEnabled =
locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled =
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if (isGPSEnabled&&isNetworkEnabled){
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,

MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

Log.d("Network", "Network");
if (locationManager != null) {
location =
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}

if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,

MIN_TIME_BW_UPDATES,MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

Log.d("GPS Enabled", "GPS Enabled");


if (locationManager != null) {

84
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
}
return location;
}

public void stopUsingGPS(){


if(locationManager != null){
locationManager.removeUpdates(GPSTracker.this);
}
}
public double getLatitude(){
if(location != null){
latitude = location.getLatitude();
}
return latitude;
}

public double getLongitude(){


if(location != null){
longitude = location.getLongitude();
}
return longitude;

85
}
publicbooleancanGetLocation() {
returnthis.canGetLocation;
}
public void showSettingsAlert(){
AlertDialog.BuilderalertDialog = new AlertDialog.Builder(mContext);
alertDialog.setTitle("GPS is settings");
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterfacedialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}

@Override
public void onLocationChanged(Location location) {
}

@Override
public void onProviderDisabled(String provider) {
}

@Override
public void onProviderEnabled(String provider) {
}

86
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}

@Override
publicIBinderonBind(Intent arg0) {
return null;
}
}

OUTPUT:

RESULT:
Thus a native application that uses GPS location information was developed and executed
87
successfully.
Ex No: 8 Develop an application for speech recognition
Date :

Aim:
To develop an application for speech recognition.

Procedure:

Creating a New project:


⮚ Open Android Studio and then click on File -> New -> New project.
⮚ Then type the Application name as “ex.no.8″ and click Next. 
⮚ Then select the Minimum SDK as shown below and click Next.
⮚ Then select the Empty Activity and click Next. 
⮚ Finally click Finish.
⮚ It will take some time to build and load the project.
⮚ After completion it will look as given below.
Designing layout for the Android Application:
⮚ Click on app -> res -> layout -> activity_main.xml.
⮚ Now click on Text as shown below.
⮚ Then delete the code which is there and type the code as given below.

Code for Activity_main.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"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar1" style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/toggleButton1"

88
android:layout_marginTop="28dp"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/progressBar1"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp" />
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:text="ToggleButton" />
</RelativeLayout>

Java Coding for the Android Application:


⮚ Click on app -> java -> com.example.exno8 ->MainActivity.
⮚ Then delete the code which is there and type the code as given below.

Code for MainActivity.java:


Package com.example.temp;
Import android.Manifest;
Import android.content.Intent;
Import android.content.pm.PackageManager;
Import android.os.Bundle;
Import android.speech.RecognitionListener;
Import android.speech.RecognizerIntent;
Import android.speech.SpeechRecognizer;
Import androidx.annotation.NonNull;

89
Import androidx.appcompat.app.AppCompatActivity;
Import androidx.core.app.ActivityCompat;
Import android.util.Log;
Import android.view.View;
Import android.widget.CompoundButton;
Import android.widget.ProgressBar;
Import android.widget.TextView;
Import android.widget.Toast;
Import android.widget.ToggleButton;
Import ava.util.ArrayList;
public class MainActivity extends AppCompatActivity implements
RecognitionListener {
private static final int REQUEST_RECORD_PERMISSION = 100;
privateTextViewreturnedText;
privateToggleButtontoggleButton;
privateProgressBarprogressBar;
privateSpeechRecognizer speech = null;
private Intent recognizerIntent;
private String LOG_TAG = "VoiceRecognitionActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
returnedText = findViewById(R.id.textView1);
progressBar = findViewById(R.id.progressBar1);
toggleButton = findViewById(R.id.toggleButton1);
progressBar.setVisibility(View.INVISIBLE);
speech = SpeechRecognizer.createSpeechRecognizer(this);
Log.i(LOG_TAG, "isRecognitionAvailable: " +
SpeechRecognizer.isRecognitionAvailable(this));
speech.setRecognitionListener(this);
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,"US-
en");

90
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3);
toggleButton.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButtonbuttonView, booleanisChecked) {
if (isChecked) {
progressBar.setVisibility(View.VISIBLE);
progressBar.setIndeterminate(true);
ActivityCompat.requestPermissions (MainActivity.this, new String[]
{Manifest.permission.RECORD_AUDIO},
REQUEST_RECORD_PERMISSION);
} else {
progressBar.setIndeterminate(false);
progressBar.setVisibility(View.INVISIBLE);
speech.stopListening();
}
}
});
}
@Override
public void onRequestPermissionsResult(intrequestCode, @NonNull String[] permissions,
@NonNullint[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_RECORD_PERMISSION:
if (grantResults.length> 0 &&grantResults[0]==
PackageManager.PERMISSION_GRANTED) {
speech.startListening(recognizerIntent);
} else {
Toast.makeText(MainActivity.this, "Permission Denied!",
Toast .LENGTH_SHORT).show();
}

91
}
}
@Override
public void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onStop() {
super.onStop();
if (speech != null) {
speech.destroy();
Log.i(LOG_TAG, "destroy");
}
}
@Override
public void onBeginningOfSpeech() {
Log.i(LOG_TAG, "onBeginningOfSpeech");
progressBar.setIndeterminate(false);
progressBar.setMax(10);
}
@Override
public void onBufferReceived(byte[] buffer) {
Log.i(LOG_TAG, "onBufferReceived: " + buffer);
}
@Override
public void onEndOfSpeech() {
Log.i(LOG_TAG, "onEndOfSpeech");
progressBar.setIndeterminate(true);
toggleButton.setChecked(false);
}

92
@Override
public void onError(interrorCode) {
String errorMessage = getErrorText(errorCode);
Log.d(LOG_TAG, "FAILED " + errorMessage);
returnedText.setText(errorMessage);
toggleButton.setChecked(false);
}
@Override
public void onEvent(int arg0, Bundle arg1) {
Log.i(LOG_TAG, "onEvent");
}
@Override
public void onPartialResults(Bundle arg0) {
Log.i(LOG_TAG, "onPartialResults");
}
@Override
public void onReadyForSpeech(Bundle arg0) {
Log.i(LOG_TAG, "onReadyForSpeech");
}
@Override
public void onResults(Bundle results) {
Log.i(LOG_TAG, "onResults");
ArrayList<String> matches =
results .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
String text = "";
for (String result : matches)
text = result + "\n";
returnedText.setText(text);
}
@Override
public void onRmsChanged(float rmsdB) {
Log.i(LOG_TAG, "onRmsChanged: " + rmsdB);
progressBar.setProgress((int) rmsdB);
}

93
public static String getErrorText(interrorCode) {
String message;
message = "Didn't understand, please try again.";
return message;
}
}

94
OUTPUT:

RESULT:
Thus an application for speech recognition was developed and executed successfully.

95
Ex No: 9 Develop an application that creates an alert upon receiving a message
Date:

Aim:
To develop an application that creates an alert upon receiving a message.

Procedure:

Creating a New project:


⮚ Open Android Studio and then click on File -> New -> New project.
⮚ Then type the Application name as “ex.no.9″ and click Next. 
⮚ Then select the Minimum SDK as shown below and click Next.
⮚ Then select the Empty Activity and click Next. 
⮚ Finally click Finish.
⮚ It will take some time to build and load the project.
⮚ After completion it will look as given below.
Designing layout for the Android Application:
⮚ Click on app -> res -> layout -> activity_main.xml.
⮚ Now click on Text as shown below.
⮚ Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns: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">

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"

96
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="@string/notify"
android:textSize="30sp"/>

</LinearLayout>

Java Coding for the Android Application:


⮚ Click on app -> java -> com.example.exno9 ->MainActivity.
⮚ Then delete the code which is there and type the code as given below.

Code for MainActivity.java:


Package com.example.temp;

Import android.app.Notification;
Import android.app.NotificationChannel;
Import android.app.NotificationManager;
Import android.content.Context;
Import android.os.Bundle;
Import android.view.View;
Import android.widget.Button;
Import android.widget.EditText;
Import androidx.appcompat.app.AppCompatActivity;
Import androidx.core.app.NotificationCompat;

public class MainActivity extends AppCompatActivity


{
Button notify;

97
EditText e;
@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)
{
NotificationManagernotificationManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
String NOTIFICATION_CHANNEL_ID = "ID_1";
NotificationChannelnotificationChannel = new
NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications",
NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(notificationChannel);
NotificationCompat.BuildernotificationBuilder = new
NotificationCompat.Builder(MainActivity.this, NOTIFICATION_CHANNEL_ID);
notificationBuilder.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("New Message")
.setContentText(e.getText().toString());
notificationManager.notify(1, notificationBuilder.build());
}
});
}
}

98
OUTPUT:

RESULT:
Thus an application that creates an alert upon receiving a message was developed and
99
executed successfully.
Ex No: 10 Develop an application on android quiz
Date:

Aim:
To develop an application on android quiz.

Procedure:

Creating a New project:


⮚ Open Android Studio and then click on File -> New -> New project.
⮚ Then type the Application name as “ex.no.10″ and click Next. 
⮚ Then select the Minimum SDK as shown below and click Next.
⮚ Then select the Empty Activity and click Next. 
⮚ Finally click Finish.
⮚ It will take some time to build and load the project.
⮚ After completion it will look as given below.
Designing layout for the Android Application:
⮚ Click on app -> res -> layout -> activity_main.xml.
⮚ Now click on Text as shown below.
⮚ Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#FFFFFF"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:id="@+id/answer_text_view"
android:text="@string/a"

100
android:textColor="@android:color/black"
android:textSize="30sp"
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:backgroundTint="#5BD91B"
android:text="@string/true_text"
android:textSize="20sp" />
<Button
android:id="@+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:backgroundTint="#E33328"
android:text="@string/false_text"
android:textSize="20sp" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:clipToPadding="false">
<Button

101
android:id="@+id/prev_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/prev_text" />

<Button
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="1"
android:text="@string/next_text" />

</LinearLayout>
</LinearLayout>

Java Coding for the Android Application:


⮚ Create a java file app -> java -> com.example.exno10 ->Question.
⮚ Then type the code as given below.

Code for Question.java:


packagecom.example.temp;

public class Question


{
privateintanswerResId;
privatebooleananswerTrue;

public Question(intanswerResId, booleananswerTrue)


{
this.answerResId = answerResId;
this.answerTrue = answerTrue;
}

102
publicintgetAnswerResId()
{
returnanswerResId;
}
public void setAnswerResId(intanswerResId)
{
this.answerResId = answerResId;
}
publicbooleanisAnswerTrue()
{
returnanswerTrue;
}
public void setAnswerTrue(booleananswerTrue)
{
this.answerTrue = answerTrue;
}
}

Java Coding for the Android Application:


⮚ Click on app -> java -> com.example.exno10 ->MainActivity.
⮚ Then delete the code which is there and type the code as given below.

Code for MainActivity.java:


packagecom.example.temp;

importandroid.annotation.SuppressLint;
importandroid.os.Build;
importandroid.os.Bundle;
importandroid.util.Log;
importandroid.view.View;
importandroid.widget.Button;
importandroid.widget.ImageView;
importandroid.widget.TextView;
importandroid.widget.Toast;

103
importandroidx.annotation.RequiresApi;
importandroidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


private Button falseButton;
private Button trueButton;
private Button nextButton;
private Button prevButton;
privateImageView Image;
privateTextViewquestionTextView;
privateint correct = 0;
privateintcurrentQuestionIndex = 0;

private Question[] questionBank = new Question[] {


new Question(R.string.a, true),
new Question(R.string.b, false),
new Question(R.string.c, false),
new Question(R.string.d, true),
new Question(R.string.e, true),
new Question(R.string.f, false),

};

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
falseButton = findViewById(R.id.false_button);
trueButton = findViewById(R.id.true_button);
nextButton = findViewById(R.id.next_button);
prevButton = findViewById(R.id.prev_button);
questionTextView
= findViewById(R.id.answer_text_view);

104
falseButton.setOnClickListener(this);
trueButton.setOnClickListener(this);
nextButton.setOnClickListener(this);
prevButton.setOnClickListener(this);
}

@SuppressLint("SetTextI18n")
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View v)
{
switch (v.getId()) {
caseR.id.false_button:
checkAnswer(false);
break;

caseR.id.true_button:
checkAnswer(true);
break;

caseR.id.next_button:
if (currentQuestionIndex< 7) {
currentQuestionIndex
= currentQuestionIndex + 1;
if (currentQuestionIndex == 6) {
questionTextView.setText(getString(
R.string.correct, correct));
nextButton.setVisibility(
View.INVISIBLE);
prevButton.setVisibility(
View.INVISIBLE);
trueButton.setVisibility(
View.INVISIBLE);
falseButton.setVisibility(

105
View.INVISIBLE);
questionTextView.setText("Score is " + correct+ " "+ "OUT OF 6");
}
else {
updateQuestion();
}
}

break;
caseR.id.prev_button:
if (currentQuestionIndex> 0) {
currentQuestionIndex= (currentQuestionIndex - 1)% questionBank.length;
updateQuestion();
}
}
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void updateQuestion()
{
Log.d("Current","onClick: " + currentQuestionIndex);

questionTextView.setText(questionBank[currentQuestionIndex]
.getAnswerResId());
}
private void checkAnswer(booleanuserChooseCorrect)
{
booleananswerIsTrue= questionBank[currentQuestionIndex]
.isAnswerTrue();
inttoastMessageId;
if (userChooseCorrect == answerIsTrue) {
toastMessageId = R.string.correct_answer;
correct++;
}

106
else {
toastMessageId = R.string.wrong_answer;
}
Toast.makeText(MainActivity.this, toastMessageId,Toast.LENGTH_SHORT)
.show();
}
}

107
OUTPUT:

RESULT:
Thus an application on android quiz was developed and executed successfully.

108

You might also like